Consuming a WCF service from a Windows Service RRS feed

  • General discussion

  • I am trying to consume a WCF service from a windows service that has been installed "Local System".

    Using VS2010, I create the service project and add a service reference to it.

    Here is the relevant code...


    SR.ClientCredentials.Windows.ClientCredential.UserName = "TestUser"

    SR.ClientCredentials.Windows.ClientCredential.Password = "TestPassword"


    Q = SR.GetData(3)

    '--do some stuff with Q --

    The error is:

    System.ComponentModel.Win32Exception: The Security Support Provider Interface (SSPI) negotiation failed.

    The code works fine following the same process in a Windows Forms app.  Making it work inside of a service is the part I'm not getting.

    Any help is HUGELY appreciated, and any links or references devoted to the issues associated with consuming WCF services inside of Windows Services (running under Windows 7 especially) would be helpful.



    (P. S. I also posted this in a related but old thread, then realized it might be better to start a new thread since it looks like I might be experiencing a different problem)

    • Edited by Encircle Friday, January 25, 2013 5:57 PM
    • Changed type Haixia_XieModerator Monday, February 4, 2013 3:04 AM op not give feedback
    Friday, January 25, 2013 5:56 PM

All replies

  • can you enable tracing and try it out.

    I doubt your Appplication pool is not allowing.


    Friday, January 25, 2013 8:47 PM
  • The same code works in a Windows Forms app, but not in a Windows Service application.  Since it works correctly in the Windows Forms app, the app pool on the server wouldn't be the problem.  If it were, then the code wouldn't work from the Windows Forms application.  Right?
    Saturday, January 26, 2013 3:58 PM
  • As Krishna suggested, you may need enable tracing to help to dignose the actual issue.
    Monday, January 28, 2013 10:21 AM
  • Usually this problem is related to Service Identity (UPN/SPN).

    According to provided information, the  difference is that Win Forms application is run under the specific windows user and Win Service is run under "Local System".

    For example, for SPN you could define it in the config

       <serviceprincipalname value="MyServiceClass\MyHostName"/>

    or we create the endpoint with the SPN

    EndpointIdentity id = EndpointIdentity.CreateSpnIdentity("MyServiceClass\MyHostName");
    EndpointAddress addr = new EndpointAddress(new Uri(URI), id);

    Monday, January 28, 2013 2:37 PM
  • a1x,

    That makes sense.  It seems to line up with the behavior I'm getting.  I'll work through that and see what happens. 

    Tuesday, January 29, 2013 2:27 PM
  • What is the issue now?
    Wednesday, January 30, 2013 5:59 AM