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;
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>
精彩评论