我想将WSHttpBinding的消息版本设置为EnvelopeVersion.Soap11。我不知道该怎么做。谁能帮我。这是我的绑定代码
var binding = new WSHttpBinding()
{
UseDefaultWebProxy = true,
Security =
{
Mode = SecurityMode.Transport,
Transport =
{
ClientCredentialType = HttpClientCredentialType.Basic
},
},
};
编辑: 这是执行该操作的代码
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;
答案 0 :(得分:6)
为了实现这一目标,您需要在配置或代码中定义自定义绑定。
在配置中,你可以这样做:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="Soap11">
<textMessageEncoding messageVersion="Soap11" />
<httpTransport />
</binding>
</customBinding>
</bindings>
然后,在您的服务或客户端配置中,使用以下内容:
<services>
<service name="test">
<endpoint name="TestEP"
address=""
binding="customBinding"
bindingConfiguration="Soap11"
contract="IService" />
</service>
</services>
</system.serviceModel>