2011-06-27 22 views
1

我在服务上做了所有正确的设置,但当我尝试将大量JSON数据发送到我的WCF REST服务时,仍然得到相同的愚蠢400错误请求。以下是我的服务Web.config。我已经为此挣扎了3周,并没有找到答案。这是从响应异常详细信息:。将大量JSON数据发送到WCF ReST服务时收到400错误请求

“发生错误反序列化类型BuildStepResource的 对象的 最大字符串内容而读 XML数据长度配额 (8192)已被超过此配额可通过在创建XML阅读器时更改 XmlDictionaryReaderQuotas对象使用的 上的MaxStringContentLength 属性来增加 。

<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

你有没有解决这个问题?我一直面临类似的问题。 – jcreamer898

回答

1

错误消息指,同时阅读这让我相信,你需要增加对客户的MaxStringContentLength财产,除了在你的web.config被超过配额。

+0

感谢您的回复。我已经尝试使用max整数maxReceivedMessageSize =“2147483647”,但仍然收到相同的错误。 – Vincent

+0

需要在客户端进行更改。创建一个客户端应用程序,而不是仅仅使用浏览器并试一试。 –

+0

谢谢!按照建议尝试与客户端应用程序,但仍然得到相同的错误。我做了一些跟踪,发现异常是在服务器上,而不是客户端。这是我的客户端配置: – Vincent

0

我有一个WCF客户端的类似问题。您必须在客户端和服务器上配置MaxItemsInObjectGraph更大。我不知道如何在JSON中执行此操作。

+0

我在服务器上做了这个,但仍然没有工作。如果我使用REST客户端进行FireFox测试,如何在客户端上执行此操作?或者,如果我在jQuery脚本中调用PUT,该如何设置?谢谢! – Vincent

0

客户端配置 -

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

<配置> <系统。serviceModel> <的WebHttpBinding> <绑定名称= “ClientBinding” 的SendTimeout = “00:10:00” MAXBUFFERSIZE = “2147483647” maxBufferPoolSize = “2147483647” maxReceivedMessageSize = “2147483647”> Vincent

+0

它仍然不工作。 – Vincent

+0

尝试更改为WSHttpBinding – Maxim

0

试试这个在你的web.config:

<system.web> 
     <compilation debug="true" targetFramework="4.0" /> 
     <httpRuntime maxRequestLength="2147483647"/> 
    </system.web> 
相关问题