简体   繁体   中英

how to make wcf service listen for soap 1.1 and soap 1.2 (in code)

I naively made a basicbinding for 1.1 and a webhttbinding for 1.2 and added them as endpoints to the same host

    var basicBinding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
    basicBinding.Security.Transport.ClientCredentialType = clientCredType;
    s_serviceHost.AddServiceEndpoint(typeof(IFoo), basicBinding, "");

    var httpBinding = new WebHttpBinding(WebHttpSecurityMode.Transport);
    httpBinding.Security.Transport.ClientCredentialType = clientCredType;
    var httpsEndpoint = s_serviceHost.AddServiceEndpoint(typeof(IFoo), httpBinding, "");

wcf objects saying

   If two endpoints want to share the same ListenUri, they must also share the same binding object instance. 
The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config.

EDIT: maybe I need to slightly rephrase. Can the same endpoint (say mything.org/service) support 1.1 and 1.2. Ie by simply looking at the payload the wcf service will determine how to read it

When you call AddServiceEndpoint via your ServiceHost object, you are specifying "" for the address argument twice. This is being interpreted as a relative URI - relative to the base address of the ServiceHost . So both endpoints end up with the same address in this situation.

This itself is not a problem, but it becomes one when they are of different bindings which is what you have ( BasicHttpBinding and WebHttpBinding ).

From Specifying an Endpoint Address on MSDN:

If you have multiple endpoints, each of which is configured with a different binding, their addresses must be unique. Endpoints that use the same binding but different contracts can use the same address.

If you are interested into the reason why a single ListenUri in WCF cannot support multiple bindings. The Multiple Endpoints at a Single ListenUri article on MSDN states:

... endpoints at the same ListenUri must have the same binding, because they are sharing a single channel stack that listens for messages at that physical address on the machine.

To solve this problem, you need to specify a non-empty string for at least one of the endpoints. This will do the trick:

s_serviceHost.AddServiceEndpoint(typeof(IFoo), httpBinding, "http");

Related to your situation, but not to the problem:

WebHttpBinding is a binding for Web services that are exposed via HTTP requests instead of SOAP-based messaging. I believe you are looking for WSHttpBinding which supports SOAP 1.2.

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