Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Message version in code for WCF client

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;
like image 465
Amzath Avatar asked Nov 12 '10 18:11

Amzath


1 Answers

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>
like image 188
marc_s Avatar answered Nov 15 '22 22:11

marc_s