2011-01-29 99 views
4

我们正在尝试将大型XML字符串发送到WCF服务的方法和我们得到的错误WCF配置maxStringContentLength似乎并不奏效

最大字符串的内容长度 配额(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> 

回答

0

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

这个其他thread也提供了一个清晰和高效的答案,使用readerQuotas。

2

尝试添加'默认'绑定(没有指定任何名称)。 将readerQuota设置添加到此绑定。

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

这为我工作(虽然我不知道为什么在正确的命名结合readerQuotas通过WCF忽略)

1

“默认”绑定选项为我工作。我试图在名为WebHttpBinding中自定义maxStringContentLength值,但由于某种原因它没有被WCF拾起。最后我跟随了D.Tiemstra的工作,然后开始工作。

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

我不知道这些最大值是正确的,我会去的: `MAXBUFFERSIZE = 2147483647, MaxBufferPoolSize = 524288, MaxReceivedMessageSize = 2147483647, ReaderQuotas = new XmlDictionaryReaderQuotas { MaxDepth = 32, MaxStringContentLength = 8192, MaxArrayLength = 16384, MaxBytesPerRead = 4096, MaxNameTableCharCount = 1638 } – DanielV 2017-09-28 09:08:05

1

我会用这个值作为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 
}