欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

wcf教程-传递数据过大怎么配置?读取 XML 数据时,超出最大字符串内容长度配额 (8192)

发布时间:2024/3/13 65 豆豆
生活随笔 收集整理的这篇文章主要介绍了 wcf教程-传递数据过大怎么配置?读取 XML 数据时,超出最大字符串内容长度配额 (8192) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

昨天测试客户端程序与服务端wcf时,出现一个错误:


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

在wcf中其实已经配置了传递数据的大小了:maxReceivedMessageSize 获取或设置配置了此绑定的通道上可以接收的消息的最大大小。

basicHttpBinding等预定义的绑定一般具有MaxReceivedMessageSize属性,CustomBinding则需要在Transport中定义。

<binding name="TcpBindingConfig" maxBufferPoolSize="655360000000" maxBufferSize="655360000" maxReceivedMessageSize="655360000000" transferMode="Streamed">

还报上面的错误,是因为传输的数据是字符串的问题。

从网上找了一下,发现都是动态配置的。整理一下:

1、在web.config中配置:

在bingding中增加一项:

<bindings><netTcpBinding><binding name="TcpBindingConfig" maxBufferPoolSize="655360000000" maxBufferSize="655360000" maxReceivedMessageSize="655360000000" transferMode="Streamed"><readerQuotas maxDepth="32" maxStringContentLength="655360000"maxArrayLength="655360000"maxBytesPerRead="655360000" maxNameTableCharCount="655360000" /><security mode="None" /></binding></netTcpBinding><basicHttpBinding><binding name="BasicHttpBindingConfig" maxBufferPoolSize="655360000000" maxBufferSize="655360000" maxReceivedMessageSize="655360000000" sendTimeout="00:02:00" transferMode="Streamed"><readerQuotas maxDepth="32" maxStringContentLength="655360000"maxArrayLength="655360000"maxBytesPerRead="655360000" maxNameTableCharCount="655360000" /><security mode="None"/></binding></basicHttpBinding></bindings>

ReaderQuotas:获取或设置可由配置了此绑定的终结点处理的 SOAP 消息的复杂性约束。

该属性是XmlDictionaryReaderQuotasElement类型,一般需要设置该属性的MaxArrayLength、MaxStringContentLength及MaxDepth属性。

MaxItemsInObjectGraph:获取对象图中要序列化或反序列化的最大项数。

该属性属于DataContractSerializer类,需要在serviceBehaviors下的behavior节中配置。

2、在 后台 C#修改:

ServiceClient service = new ServiceClient(); (service.Endpoint.Binding as NetTcpBinding).MaxReceivedMessageSize = int.MaxValue; (service.Endpoint.Binding as NetTcpBinding).MaxBufferPoolSize = int.MaxValue; (service.Endpoint.Binding as NetTcpBinding).MaxBufferSize = int.MaxValue; 发送大数据:在WCF服务端解决NetTcpBinding binding = new NetTcpBinding();binding.MaxReceivedMessageSize= 2147483647(更改这个数字) ; 接受大数据:在WCF客户端解决NetTcpBinding binding = new NetTcpBinding();binding.ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxStringContentLength = 2147483647(更改这个数字) };




总结

以上是生活随笔为你收集整理的wcf教程-传递数据过大怎么配置?读取 XML 数据时,超出最大字符串内容长度配额 (8192)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。