在 WCF 客户端的代码中设置消息版本

发布于 2024-10-01 15:42:15 字数 1420 浏览 4 评论 0原文

我想将 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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

舟遥客 2024-10-08 15:42:15

为了实现这一点,您需要在配置或代码中定义自定义绑定。

在配置中,您可以这样做:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文