由于最大字符串内容长度配额,WCF Web服务无法反序列化

时间:2015-04-17 12:57:44

标签: c# wcf

我知道之前已经提出过这个问题,但我已经阅读了所有这些问题,并且我相信我已经实施了所有建议而且他们没有帮助。

Fiddler(最好的工具EVER!)显示整个消息都到达服务器,因此客户端(及其app.config)无关紧要。

  • 我确保readerquotas / MaxStringContentLength超过8K。
  • 我确保maxItemsInObjectGraph超过8K。
  • 我确保在端点中引用绑定和行为。
  • 我确定我确实连接到引用的端点(即URL正确)。

错误消息为:

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:deal. The InnerException message was 'There was an error deserializing the object of type MYOBJECT. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 38700.'. Please see InnerException for more details

网络配置的相关部分:

<system.serviceModel> <bindings> <basicHttpBinding> <binding name="DefaultBinding"> <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" /> </binding> </basicHttpBinding> </bindings> <behaviors> <endpointBehaviors> <behavior name="DefaultEndpointBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <services> <service name="DmsIntegrationService"> <endpoint behaviorConfiguration="DefaultEndpointBehavior" binding="basicHttpBinding" bindingConfiguration="DefaultBinding" contract="MYCONTRACT" /> </service> </services> </system.serviceModel>

我知道将所有这些数字提升到int.MaxValue是一个潜在的DOS风险。在发布之前我会降低它们。

2 个答案:

答案 0 :(得分:1)

尝试这样的事情

<binding name="DefaultBinding" maxBufferPoolSize="524288" maxBufferSize="524288" maxConnections="10" maxReceivedMessageSize="5242880"> <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </binding>

也请参阅此链接here

答案 1 :(得分:0)

尝试将这些内容放在WCF Web配置中

<system.web>
    <httpRuntime maxRequestLength="5120000" />
</system.web>
  <system.webServer>
    <urlCompression doDynamicCompression="true" doStaticCompression="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="1024000000" />
      </requestFiltering>
    </security>
  </system.webServer>