Javascript到WCF - MaxStringContentLength异常

时间:2012-02-10 03:23:33

标签: wcf

我正在使用jQuery / JavaScript客户端将AJAX请求发送到WCF REST服务(webHttpEndpoint),我收到以下异常......

System.Xml.XmlException:读取XML数据时已超出最大字符串内容长度配额(8192)。通过更改创建XML阅读器时使用的XmlDictionaryReaderQuotas对象的MaxStringContentLength属性,可以增加此配额。

这是我的system.serviceModel web.config定义...

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                               multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="MembershipBinding">
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
        <binding name="userHttps">
          <security mode="Transport" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="CommonSvcBehavior">
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
                                    membershipProviderName="AspNetSqlMembershipProvider" />
          </serviceCredentials>
          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
                                roleProviderName="MySqlRoleProvider" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="AuthenticationServiceTypeBehaviors">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name=""
                          crossDomainScriptAccessEnabled="false"
                          helpEnabled="true"
                          automaticFormatSelectionEnabled="true" />
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>

我尝试添加以下绑定.....但它没有生效...

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

你能帮忙吗?

2 个答案:

答案 0 :(得分:1)

我想出来......需要在standardEndPoints

中更改以下内容
<standardEndpoints>
  <webHttpEndpoint>
    <standardEndpoint name=""
                      crossDomainScriptAccessEnabled="false"
                      helpEnabled="true"
                      automaticFormatSelectionEnabled="true">
      <readerQuotas maxDepth="2147483647"
                    maxStringContentLength="2147483647"
                    maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647" />       
    </standardEndpoint>
  </webHttpEndpoint>
</standardEndpoints>

答案 1 :(得分:0)

如果要覆盖绑定的默认值,则需要将绑定名称分配给bindingConfiguration部分中<endpoint>元素的<service>属性,如下所示:< / p>

<services>
  <service name="MyService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="MembershipBinding" contract="MyService.IMyContract" />
  </service>
</services>

<services>部分位于<system.serviceModel>部分。

我不是100%确定这适用于RESTful WCF,但是从我做过的研究看起来应该是这样。

要记住的重要一点是,您必须告诉服务对于给定端点使用什么绑定,如果您需要该绑定上的设置值而不是默认值,则需要分配您设置的绑定直到终点。