WCF detecting which binding was called
I have a WCF web service, and it can be called through more than one endpoint. How do I dynamically detect which endpoint was used?
For instance, my service can be called through HTTPS with a binding named "WSHttpBinding_TransportSecurity_IMyService" or through a Windows Integrated Authentication binding named "WSHttpBinding_WindowsSecurity_IMyService". Depending on which one was called, I need to take a 开发者_JAVA百科slightly different action to determine the identity of the client.
How can I approach this? (If any more specific details are needed I can provide them.)
If you need to know the source binding to determine the callers identity you are doing something wrong. Your service should be protocol agnostic. Identity management can be accomplished using authentication policies.
Can't you try to obtain current user Windows identity
WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
and if it's NULL try to use username/password version?
Answering the original question:
You can use the To property of the IncomingMessageHeaders, which gives you an URI that has been used by the client.
OperationContext contect = OperationContext.Current;
MessageHeaders messageHeaders = contect.IncomingMessageHeaders;
Uri To = messageHeaders.To;
精彩评论