Setting Message version in code for WCF client
Asked Answered
H

1

12

I want to set message version for WSHttpBinding to EnvelopeVersion.Soap11. I don't know how to do that. Can any one help me. Here is my binding code

var binding = new WSHttpBinding()
        {
            UseDefaultWebProxy = true,
            Security =
            {
                Mode = SecurityMode.Transport,
                Transport =
                {
                    ClientCredentialType = HttpClientCredentialType.Basic
                },
            },
        };

EDIT: here is the code to do that

TransportBindingElement transportElement = null;

        transportElement = new HttpsTransportBindingElement();

        ((HttpsTransportBindingElement)transportElement).AuthenticationScheme = AuthenticationSchemes.Basic;
        ((HttpsTransportBindingElement) transportElement).KeepAliveEnabled = false;

        var messegeElement = new TextMessageEncodingBindingElement
        {
            MessageVersion = MessageVersion.CreateVersion(EnvelopeVersion.Soap11, AddressingVersion.None),
            ReaderQuotas =
                    {
                        MaxArrayLength = 200000,
                        MaxBytesPerRead = 200000,
                        MaxDepth = 200000,
                        MaxNameTableCharCount = 200000,
                        MaxStringContentLength = 200000
                    }
        };

        var binding = new CustomBinding(messegeElement, transportElement);
        return binding;
Hugo answered 12/11, 2010 at 18:38 Comment(1)
Thanks it's the answer I was looking for a long time !Gonroff
P
8

In order to achieve this, you need to define a custom binding - in config or in code.

In config, you'd do it something like this:

<system.serviceModel>
   <bindings>
      <customBinding>
         <binding name="Soap11">
            <textMessageEncoding messageVersion="Soap11" />
            <httpTransport />
         </binding>
      </customBinding>
   </bindings>

and then, in your service or client config, use something like this:

   <services>
      <service name="test">
         <endpoint name="TestEP"
             address=""
             binding="customBinding"
             bindingConfiguration="Soap11"
             contract="IService" />
      </service>
   </services>
</system.serviceModel>
Persecution answered 12/11, 2010 at 19:41 Comment(1)
@amz: you should update your original question with this solution; there you can properly format and present it - here in comments, it's a messy affair....Persecution

© 2022 - 2024 — McMap. All rights reserved.