读书人

WCF 步骤参数字符长度超过8192报错,请

发布时间: 2013-04-26 16:27:53 作者: rapoo

WCF 方法参数字符长度超过8192报错,请求指导。
格式化程序尝试对消息反序列化时引发异常: 对操作“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>



客户端配置:


name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>


??WCF?.net8192? WCF? String 8192
[解决办法]
不知道win7有没有,server2008可以用服务跟踪查看器查看具体错误日志。

读书人网 >asp.net

热点推荐