Hosting WCF in IIS with (Impersonation = ImpersonationOption.Required)
I have a WCF service (MyService.svc) that im hosting under IIS 7.5. My .svc is under the same virtual directory as the Web App itself. I am trying to get some of my service operations to require user impersonation:
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
I have used basicHttpBinding with:
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
After publishing this, i go to http:///MyService.svc. This is when i get the following error:
The contract operation 'HelloWorld' requires Windows identity for automatic impersonation. A Windows identity that represents the caller is not provided by binding ('BasicHttpBinding','http://tempuri.or开发者_如何学编程g/') for contract ('IMyService','http://MyService'.
* Update / Fix * I found my issue. I was not providing the namespace component of my service name in the web.config. This was making the whole thing barf.
<services>
<service name="**MyNamespace**.MyService" behaviorConfiguration="MyServiceBehavior">
...
</service>
</services>
Based on the error message, it sounds like you didn't provide credentials when you created the proxy? I haven't done impersonation in WCF, but I'd recommend looking at providing credentials (either via the config file or programatically at proxy creation).
精彩评论