locked
ASP.NET fails to call WCF in Windows Service RRS feed

  • Question

  • Hello,

    I have a WCF in a Windows Service using netTcpBinding.  The clientCredentialType is Windows.  Calling this WCF from other Windows Services works fine.  But when I try to call from ASP.NET, it fails saying "[Win32Exception (0x80004005): The logon attempt failed]
    [InvalidCredentialException: The server has rejected teh client credentials.]".  I have <system.serviceModel> section in my web.config pretty much the same as the other windows services' app.config which successfully call the WCF in the Windows Service; (all of my Windows Services are running as "Local System").  Is there something special that I need to do in ASP.NET application so that calling a WCF will work?
    By the way, when I run the ASP.NET in debug mode from Visual Studio 2008, calling WCF works okay.
    Thursday, November 5, 2009 4:28 PM

Answers

  • Hi Moon,

    I think for windows credentials, you should not simply set the Username and Password properties, but create a new NetworkCredential instance and assign it to your proxy(or channelfactory). e.g.

     
    factory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password");


    Also, when you do not explicitly supply a credential, the WCF runtime will use your current execution account as the windows credentials. For your case, it should be the ASP.NET process account(IIS pool account). I think the ASP.NET process account is different from your windows service client's execution account or your logon user account.

    Btw, you mentioned that you're using IIS 6 on windows 2008 server? As far as I know, windows 2008 server and windows 7 are using IIS 7, have you double checked the IIS version?








    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Moon Chung Thursday, November 12, 2009 1:40 PM
    Thursday, November 12, 2009 10:33 AM

All replies

  • Sounds like you need to configure IIS to run your web application with the proper credentials. I'm not sure exactly how that would work but I'd guess you could find that in google pretty quick.

    "Not sure of the version of IIS you are using but I believe if you set/change the identity of the application pool for your website this would do what you are looking for."

    http://serverfault.com/questions/69935/running-iis-application-with-different-user-credentials
    If my response answers your question, please mark it as the "Answer" by clicking that button above my post.

    My blog: http://www.RyanVice.net/
    Thursday, November 5, 2009 7:14 PM
  • Ryan,

    Thank you for the reply.
    My IIS is version 6.0 running under Windows 2008 64 bit OS.

    I tried to set the identity for my application as following but the result is the same.

    <

     

     

    identity impersonate="true" userName="myusername" password="mypassword"/>

    Why do I need a proper credential for my web application?
    I am already supplying a proper credential when I make a WCF call as following:

    string svName = MyServerName;
    string address = string.Format(WcfConstants.__RtdSvServiceUrl, svName);
    InstanceContext callbackInstance = new InstanceContext(this);
    DuplexChannelFactory<IRtdSvService> factory = new DuplexChannelFactory<IRtdSvService>(callbackInstance, "IRtdSvService",
     new EndpointAddress(new Uri(address)));
    factory.Credentials.Windows.ClientCredential.UserName = "MyUsername";
    factory.Credentials.Windows.ClientCredential.Password = "MyPassword";
    IRtdSvService rtdSvService = factory.CreateChannel();
    rtdSvService.MyFuctionCall(rtdServer);
    factory.Close();
    Thursday, November 5, 2009 9:40 PM
  • Does anyone have any idea how to call WCF that is hosted in Windows Service from ASP.NET?
    Thanks.
    Tuesday, November 10, 2009 5:24 PM
  • Hi Moon,

    I think for windows credentials, you should not simply set the Username and Password properties, but create a new NetworkCredential instance and assign it to your proxy(or channelfactory). e.g.

     
    factory.Credentials.Windows.ClientCredential = new System.Net.NetworkCredential("username", "password");


    Also, when you do not explicitly supply a credential, the WCF runtime will use your current execution account as the windows credentials. For your case, it should be the ASP.NET process account(IIS pool account). I think the ASP.NET process account is different from your windows service client's execution account or your logon user account.

    Btw, you mentioned that you're using IIS 6 on windows 2008 server? As far as I know, windows 2008 server and windows 7 are using IIS 7, have you double checked the IIS version?








    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Moon Chung Thursday, November 12, 2009 1:40 PM
    Thursday, November 12, 2009 10:33 AM
  • Hi Steven,

    Thank you for the reply.  It worked when I tried your suggestion.
    Also, you are right that I have IIS 7.

    Thanks.
    Moon
    Thursday, November 12, 2009 1:40 PM