我在服务上做了所有正确的设置,但是当我尝试将大量JSON数据输出到我的WCF REST服务时,仍然得到相同的愚蠢的400 Bad Request。下面是我的服务Web.config。我已经挣扎了3个星期,但没有找到答案。这是响应中的异常细节:
“反序列化出错了 BuildStepResource类型的对象。该 最大字符串内容长度配额 (8192)在阅读时已超出 XML数据。这个配额可能会增加 通过更改MaxStringContentLength 物业 使用的XmlDictionaryReaderQuotas对象 在创建XML阅读器时。“
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<bindings>
<webHttpBinding>
<binding name="nonSSLBinding" maxReceivedMessageSize="4194304" receiveTimeout="01:00:00" sendTimeout="01:00:00" >
<security mode="None">
<transport clientCredentialType="Ntlm"/>
</security>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
</binding>
<binding name="sslBinding" maxReceivedMessageSize="4194304" receiveTimeout="01:00:00" sendTimeout="01:00:00" >
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="webBehavior" name="serviceEndpoints">
<endpoint address="" binding="webHttpBinding" contract="ISWCRestService" bindingConfiguration="nonSSLBinding" behaviorConfiguration="customBehavior"/>
<endpoint address="" binding="webHttpBinding" contract="ISWCRestService" bindingConfiguration="sslBinding" behaviorConfiguration="customBehavior"/>
<endpoint address="" binding="webHttpBinding" contract="IXmlEndpoint" bindingConfiguration="nonSSLBinding" behaviorConfiguration="customBehavior"/>
<endpoint address="" binding="webHttpBinding" contract="IXmlEndpoint" bindingConfiguration="sslBinding" behaviorConfiguration="customBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="webBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="customBehavior">
<webHttp automaticFormatSelectionEnabled="false" helpEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
答案 0 :(得分:1)
错误消息是指在读取时超出配额,这使我相信您需要增加客户端端的MaxStringContentLength属性,而不是在您的网络上的.config。
答案 1 :(得分:0)
我遇到了与WCF客户端类似的问题。您必须在客户端和服务器上将MaxItemsInObjectGraph配置为更大。我不知道如何在JSON中这样做。
答案 2 :(得分:0)
客户端配置 -
<binding name="yourBinding" maxReceivedMessageSize="2147483647">
<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
答案 3 :(得分:0)
在你的web.config中试试这个:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2147483647"/>
</system.web>