The server has rejected the client credentials, WCF as Windows Service

后端 未结 4 1479
误落风尘
误落风尘 2020-12-31 10:40

I am able to connect to my WCF service with the Win-form application, however i am not able to do so with my windows service. Whenever i fire open() to the proxy it throws t

4条回答
  •  时光取名叫无心
    2020-12-31 10:44

    Basically what is happening is that your calling service doesn't have the appropriate credentials, like you would have when calling from WinForms. What you need is some impersonation. It takes a bit of setting up, and is kind of annoying, but it will work.

    Luckily MSDN has a nice little walkthrough.
    http://msdn.microsoft.com/en-us/library/ms731090.aspx

    There is some more general information on the topic here:
    http://msdn.microsoft.com/en-us/library/ms730088.aspx

    UPDATE:
    Setting impersonation flags is not enough. You have to actually impersonate a credential to make it work. For example:

      // Let's assume that this code is run inside of the calling service.
      var winIdentity = ServiceSecurityContext.Current.WindowsIdentity;
      using (var impContext = winIdentity.Impersonate())
      {
        // So this would be the service call that is failing otherwise.
        return MyService.MyServiceCall();
      }
    

提交回复
热议问题