【问题标题】:WCF - configuration for custom bindingWCF - 自定义绑定的配置
【发布时间】:2011-06-05 14:07:30
【问题描述】:

我正在尝试通过配置将自定义消息编码器插入 WCF 管道。之前我使用的是开箱即​​用的“NetTcpBinding”,我的配置文件看起来像

<bindings>
      <netTcpBinding>
         <binding name="DefaultNetTcpBinding"
                 maxBufferSize="26214400"
                 maxReceivedMessageSize="26214400"
                 maxBufferPoolSize="26214400"
                 listenBacklog="1000"
                 maxConnections="1000"
                 closeTimeout="00:01:00"
                 openTimeout="00:10:00"
                 receiveTimeout="00:01:30"
                 sendTimeout="00:01:00">
          <security mode="None"/>
          <reliableSession ordered="true" inactivityTimeout="00:01:30" enabled="true"/>
        </binding>
      </netTcpBinding>
</bindings>

为了插入自定义编码器,我尝试遵循自定义绑定配置

<bindings>
      <customBinding>
          <binding name="compactBinding">
              <compactMessageEncoding>
                          <binaryMessageEncoding/>
              </compactMessageEncoding>
              <tcpTransport />
          </binding>
      </customBinding>
  </bindings>

它工作正常。但我仍然想要我之前的设置,如 maxBufferSize、maxReceivedMessageSize、maxBufferPoolSize 等。似乎&lt;customBinding&gt; 下的&lt;binding&gt; 元素只有 closeTimeout、openTimeout、receiveTimeout、sendTimeout。

如何传递其他信息?

谢谢

【问题讨论】:

    标签: c# wcf c#-4.0


    【解决方案1】:

    尝试添加一个 HttpTransportBindingElement。我认为这对你有用。这是link

    【讨论】:

    • 但我不想要 httptransport。我已经在使用 tcpTransportBindingElement。可以在上面设置属性吗?
    • 抱歉,错过了。是的,您也可以在 tcpTransport 元素上设置属性。这也是一个链接。 msdn.microsoft.com/en-us/library/…
    【解决方案2】:
    <customBinding>
          <binding>
           ...
            <tcpTransport listenBacklog ="100" maxBufferPoolSize ="524288" maxBufferSize ="2147483647" maxReceivedMessageSize ="2147483647"/>
           ...
          </binding>
    </customBinding>
    

    【讨论】:

    • 代码示例很好,但请添加一些说明。
    • 这里没有超时设置
    【解决方案3】:

    尝试在这样的代码中添加配置:

    ((CustomBinding)servicio.Endpoint.Binding).Elements.Find<TransportBindingElement>().MaxReceivedMessageSize = int.MaxValue;
    

    并且还在 web.config 中添加一个 readerQuotas:

    <readerQuotas maxDepth="90000" maxStringContentLength="2147483647"
                             maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-19
      • 1970-01-01
      相关资源
      最近更新 更多