格式化程序尝试对消息反序列化时引发异常: 对操作“GetData”的请求消息正文进行反序列化时出现错误。读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。 行 1,位置 10125。一直出现这个错误,怎么修改都不正确。
网上也搜了下,找到的修改办法试了也不起作用。
下面是我根据网上找的一些内容做的一些修改,但是运行起来还是出问题,求指导。运行环境,win7,vs2010,mvc3服务器端代码:namespace WcfService
{
    public class Service1 : IService1
    {
        public int GetData(string value)
        {
            value = value == null ? "" : value;
            return value.Length;
        }
    }
}
namespace WcfService
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        int GetData(string value);
    }}客户端代码:Service1Client wcf_client = new Service1Client();
            string itemstr = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
            string teststr = "";
            for (int i = 0; i < 100; i++)
            {
                teststr += itemstr;
            }            int b = teststr.Length;
            int a = wcf_client.GetData(teststr);
            wcf_client.Close();
服务器端配置:<system.serviceModel>
 
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
        
        <behavior name="A">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
        
      </serviceBehaviors>
    </behaviors>    <services>
      <service behaviorConfiguration="A" name="WcfService.IService1.GetData">
        <endpoint address="" bindingConfiguration="BBB" binding="basicHttpBinding" contract="WcfService.IService1.GetData"/>
      </service>
    </services>    <bindings>
      <basicHttpBinding>
        <binding name="BBB" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
    
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
客户端配置:<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:2382/Service1.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService1" contract="wcfService.IService1"
        name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>
   WCF .net8192 WCF String8192

解决方案 »

  1.   

    不知道win7有没有,server2008可以用服务跟踪查看器查看具体错误日志。
      

  2.   

    最后解决了,找到问题是
    <services>
          <service behaviorConfiguration="A" name="WcfService.IService1.GetData">
            <endpoint address="" bindingConfiguration="BBB" binding="basicHttpBinding" contract="WcfService.IService1.GetData"/>
          </service>
        </services>service 的name属性只需要写到命名空间+类名就可以了,不需要具体到方法名。
    endpoint 的contract属性同样只需要命名空间+接口名就行了。