【问题标题】:Why doesn't WCF Service Reference keep some settings after metadata exchange?为什么 WCF 服务参考在元数据交换后不保留某些设置?
【发布时间】:2012-02-14 15:51:18
【问题描述】:

我在我的 WCF 服务的 app.config 文件中定义这样的绑定:

<bindings>
  <netTcpBinding>
    <binding name="Binding1"
             closeTimeout="00:01:00"
             openTimeout="00:01:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:01:00"
             transactionFlow="false"
             transferMode="Buffered"
             transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard"
             listenBacklog="10"
             maxBufferPoolSize="524288"
             maxBufferSize="524288"
             maxConnections="10"
             maxReceivedMessageSize="524288">
      <readerQuotas maxDepth="32"
                    maxStringContentLength="8192"
                    maxArrayLength="16384"
                    maxBytesPerRead="4096"
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true"
                       inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" algorithmSuite="Default" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>

请注意,我已将 maxBufferSizemaxReceivedMessageSize 设置为 524288 字节。在我的客户项目中,当我单击“添加服务引用”时,我能够发现并添加我的服务。但它会像这样填写我客户的app.config 文件

<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_AgileService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
      hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
      maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" algorithmSuite="Default" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>

我很好奇为什么maxBufferSizemaxReceivedMessageSize 在我客户的app.config 中恢复为默认值。这些设置是否分别适用于客户端和服务器?换句话说,客户端和服务器可以各自有自己的消息大小限制吗?

我还需要在客户端上做些什么来确保客户端愿意发送 524288 字节的消息吗? (我只关心客户端->服务器通信)

【问题讨论】:

    标签: .net wcf wcf-binding nettcpbinding


    【解决方案1】:

    是的,这些设置特定于客户端或服务器(取决于您处理的配置)。 MaxReceivedMessageSize 仅适用于服务或客户端正在接收的消息的大小,而不适用于正在发送的消息的大小。

    您可能还需要在ReaderQuotas 中增加MaxStringContentLength 以处理更大的消息。此外,您需要确保在服务的配置文件中引用服务端点中的 Binding1 配置(通过 bindingConfiguration 属性),否则您的服务将恢复为 NetTcpBinding 的默认设置。

    例子:

    <services>
      <service behaviorConfiguration="MyBehavior" name="MyService">
        <endpoint address="" binding="netTcpBinding"
                  bindingConfiguration="Binding1"
                  contract="MyService.IMyContract" />
      </service>
    </services>
    

    【讨论】:

    • 很好的答案 - 关于 MaxStringContentLength 的非常有用的信息
    【解决方案2】:

    注意 MaxReceivedMessageSize 的名称。它与数据的接收者准备接受的数据大小有关。因此,客户端和服务很可能需要不同的值 - 所以这些不是从元数据生成的值的一部分

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 2018-07-22
      • 2023-04-09
      • 2010-11-29
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多