【问题标题】:wcf configuration maxStringContentLength does not seem to be workingwcf 配置 maxStringContentLength 似乎不起作用
【发布时间】:2011-01-29 01:21:51
【问题描述】:

我们正在尝试向 WCF 中的服务方法发送一个大的 xml 字符串,但我们收到了错误

最大字符串内容长度 配额 (8192) 已超出,而 读取 XML 数据。

该错误建议增加maxstringcontentlength,尽管我们不确定是否应该在客户端或服务器端或两者兼而有之。我们已经尝试过两者,但我们似乎仍然得到错误。我将在下面发布客户端和服务配置。我假设他们中的一个或两个存在问题,阻止了它的工作。

有什么建议吗?

客户:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_ITESTService" 
                closeTimeout="00:01:00" openTimeout="00:01:00" 
                receiveTimeout="00:10:00" sendTimeout="00:01:00"
                allowCookies="false" bypassProxyOnLocal="false" 
                hostNameComparisonMode="StrongWildcard"
                maxBufferSize="65536" maxBufferPoolSize="524288"  
                maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" 
                transferMode="Buffered" useDefaultWebProxy="true">
               <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
                    maxArrayLength="2147483647" maxBytesPerRead="4096" 
                    maxNameTableCharCount="2147483647" />
               <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint name="BasicHttpBinding_ITESTService"  
            address="http://localhost/TESTService.svc" 
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_ITESTService" 
            contract="TESTService.ITESTService" />
    </client>
</system.serviceModel>

服务器:

<system.serviceModel>
   <bindings>
      <basicHttpBinding>
          <binding
              name="BasicHttpBinding_Service1"
              maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="32" 
              maxStringContentLength="2147483647" maxArrayLength="2147483647"
              maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
       <service name="TESTService">
          <endpoint name="BasicHttpBinding_Service1"
              address="http://localhost/TESTService.svc"
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_Service1"
              contract="ITESTService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

【问题讨论】:

    标签: wcf configuration soap


    【解决方案1】:

    尝试添加一个“默认”绑定(不指定任何名称)。 将 readerQuota 设置添加到此绑定。

    然后,您甚至可以从您实际使用的命名绑定中删除 readerQuota 设置。

    这对我有用(尽管我不确定为什么 WCF 会忽略正确命名绑定上的 readerQuotas

    【讨论】:

      【解决方案2】:

      'default' 绑定选项对我有用。我正在尝试在命名的 WebHttpBinding 中自定义 maxStringContentLength 值,但由于某种原因它没有被 WCF 拾取。最后我跟着 D.Tiemstra 工作,然后它开始工作。

          <webHttpBinding>         
          <binding  maxReceivedMessageSize="2147483647" > 
            <readerQuotas maxDepth="2147483647"
             maxStringContentLength="2147483647"
             maxArrayLength="2147483647"
             maxBytesPerRead="2147483647"
             maxNameTableCharCount="2147483647" />
          </binding>
        </webHttpBinding>
      

      【讨论】:

      • 我不认为这些最大值是正确的,我会选择:MaxBufferSize = 2147483647, MaxBufferPoolSize = 524288, MaxReceivedMessageSize = 2147483647, ReaderQuotas = new XmlDictionaryReaderQuotas { MaxDepth = 32, MaxStringContentLength = 8192, MaxArrayLength = 16384, MaxBytesPerRead = 4096, MaxNameTableCharCount =1638 }
      【解决方案3】:

      thread 详细解释了如何正确指定服务器和客户端上的绑定设置以更改 MaxStringContentLength。

      另一个thread 也提供了关于使用 readerQuotas 的清晰有效的答案。

      【讨论】:

        【解决方案4】:

        我会将此值用于 WCF 配置(以编程方式):

        Security = { Mode = SecurityMode.None},
        CloseTimeout = TimeSpan.MaxValue,
        OpenTimeout = TimeSpan.MaxValue,
        SendTimeout = TimeSpan.FromMinutes(5),
        ReceiveTimeout = TimeSpan.FromMinutes(5),
        MaxBufferSize = 2147483647,
        MaxBufferPoolSize = 524288,
        MaxReceivedMessageSize = 2147483647,
        ReaderQuotas = new XmlDictionaryReaderQuotas
        {
           MaxDepth = 32,
           MaxStringContentLength = 8192,
           MaxArrayLength = 16384,
           MaxBytesPerRead = 4096,
           MaxNameTableCharCount =1638
        }
        

        【讨论】:

          猜你喜欢
          • 2011-12-20
          • 2018-06-07
          • 2018-09-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多