简体   繁体   中英

WCF: Using Multiple Authentication Schemes on same endpoint

I have a WCF service which i host as a Windows Service. I need to support both Windows and NTLM authentication on the service endpoint.

I came across a MSDN page which explains exactly the same with .NET 4.5, here's the link:

http://msdn.microsoft.com/en-us/library/hh556235(v=vs.110).aspx

Going by this, I configured my service endpoint in code as explained in the self-hosted services section of the above link. But, when I test this doesn't work. I captured the traffic and observed that there's no HTTP 401 challenge sent by the service, instead, it directly fails with HTTP 400 Bad Request error. I believe that should have been a HTTP 401 challenge sent to client.

Did I miss anything here?

Well it is possible and I could make it work after 4 days of struggle, the errors HTTP Bad Request does not indicate the problem. But, As I added service metadata behavior with HttpGetEnabled it worked.

Also, ensure if you define ServiceAuthenticationBehavior you do mark the ClientCredentialType to InheritedFromHost. This would ensure the authentication schemes as indicated by the ServiceAuthenticationBahavior are applied.

Hope, this would save someone else's 4 days! :)

You can have multiple authentication schemes running within the same Windows service, but not at the same end point - that's not possible.

For instance, I can create and IIS or self-host a web service called NeedHelp that uses three kinds of authentication, and here are my endpoints:

http:/ /NeedHelp:8001/NoAuth

http:/ /NeedHelp:8002/WindowsAuth

http:/ /NeedHelp:8003/CertAuth

All of those can run under the same web service, all hosted by IIS or self hosted as a Windows service. But they all need separate port addresses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM