做了一个wcf的小例子,遇到一个奇怪的问题,传送大数据量总出错
各位老大,今天做了一个wcf的小例子,遇到一个奇怪的问题,每次传送大数据量总报错,传送了10000个对象,一个对象里面有6个字符串,按理说应该可以传2G的,实在找不到原因。。。哪个老大对wcf比较熟悉,帮看下报错:
格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetAllBooksResult。InnerException 消息是“对象图中可以序列化或反序列化的项目数目上限为“65536”。请更改对象图或增加 MaxItemsInObjectGraph 的配额。 ”。有关详细信息,请参阅 InnerException。
我的服务端配置文件:
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="endPointBehavior" >
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="Services.BookService">
<endpoint address="basic" behaviorConfiguration="endPointBehavior"
binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration"
contract="Services.IBookService" listenUriMode="Explicit" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8081/BookService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration" textEncoding="UTF-8" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00" >
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
客户端调用的代码:
string serviceUrl = @"http://localhost:8081/BookService/basic";
BasicHttpBinding bing = new BasicHttpBinding(BasicHttpSecurityMode.None)
{
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
MaxBufferPoolSize = 2147483647,
ReceiveTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 10, 0)
};
WS.BookServiceClient client = new Client.WS.BookServiceClient(bing, new EndpointAddress(serviceUrl));
client.GetAllBooksCompleted += new EventHandler<Client.WS.GetAllBooksCompletedEventArgs>(client_GetAllBooksCompleted);
client.GetAllBooksAsync();
--------------------编程问答-------------------- 路过帮顶~~ --------------------编程问答-------------------- <binding name="basicHttpBindingConfiguration" textEncoding="UTF-8" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" openTimeout="00:10:00" sendTimeout="00:10:00" receiveTimeout="00:10:00" >
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
MaxBufferPoolSize = 2147483647,
ReceiveTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 10, 0)
这些设置逐个试着放大些,比如1000倍或更大,看看是卡在那里了, --------------------编程问答-------------------- 一个没有分了的菜鸟,发贴纯粹是为了得分,谢谢楼主。 --------------------编程问答-------------------- MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647,
MaxBufferPoolSize = 2147483647,
ReceiveTimeout = new TimeSpan(0, 10, 0),
SendTimeout = new TimeSpan(0, 10, 0)
这些设置逐个试着放大些,比如1000倍或更大,看看是卡在那里了,
不可能放大了,2147483647是最大了,2147483647相当于2g了啊 --------------------编程问答-------------------- 那你就逐个放异常,看看是哪里超了? --------------------编程问答-------------------- 就是服务返回数据的时候显示超了,但我只是传送了10000个对象,一个对象里面有6个字符串,而且设置了maxItemsInObjectGraph="2147483647",相当于2g --------------------编程问答-------------------- --------------------编程问答-------------------- 还没解决呢啊。。。。 --------------------编程问答-------------------- 人鸟? --------------------编程问答-------------------- 字符串不是对象么?
不要胡乱修改默认配置值。考虑一下你有没有必要一定要这样去传送数据。 --------------------编程问答--------------------
我也正遇到这个问题,请问楼主,该问题得到解决了吗?
可否分享下解决方法~~~
--------------------编程问答-------------------- 检查配置文件,把值调大。传送这么多的对象,少传一些看看 --------------------编程问答-------------------- 最近也在研究WCF,遇到同样的问题,从数据库中获取到100000条数据,有20列,每列20个汉字,算下来差不多70MB数据,结果引发类型为“System.OutOfMemoryException”的异常。
不知道楼主问题解决没有?
补充:.NET技术 , C#