WCF中数据的传输问题

Jonea 2009-06-30 04:09:32

基于NetTcpBinding的WCF程序

已经对传输的数据进行了最大化了

tcpBinding.MaxReceivedMessageSize = int.MaxValue;
tcpBinding.MaxBufferSize = int.MaxValue;
tcpBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
tcpBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;

数据大小为2114以下全部正常

可是当传数据传输入2115行以上时.弹出错误

套接字连接已中止。这可能是由于处理消息时出错或远程主机超过接收超时或者潜在的网络资源问题导致的。本地套接字超时是“00:01:00”

这大概是什么问题啊?
...全文
241 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
V68V6 2009-07-01
  • 打赏
  • 举报
回复

友情UP
参考一下,也不知道有无帮助
http://www.cnblogs.com/sf4651896/
Jonea 2009-07-01
  • 打赏
  • 举报
回复
问题找到了.
是MaxItemsInObjectGraph用了默认大小

感谢大家的帮助.
主要是我没用XML配置WCF.全用代码写的.

MaxItemsInObjectGraph用程序写还比较麻烦
用Attribute设置,把代码贴出来供大家参考下吧
public class CustomDataAttribute : Attribute, IOperationBehavior
{
private bool _preserveReferences = false;
private int _maxItemsInObjectGraph = 65536;

public CustomDataAttribute(bool preserveReferences, int maxItemsInObjectGraph)
{
_preserveReferences = preserveReferences;
_maxItemsInObjectGraph = maxItemsInObjectGraph;
}

public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters)
{ }

public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
{
IOperationBehavior innerBehavior = new CustomDataOperationBehavior(description, _preserveReferences, _maxItemsInObjectGraph);
innerBehavior.ApplyClientBehavior(description, proxy);
}

public void ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
{
IOperationBehavior innerBehavior = new CustomDataOperationBehavior(description, _preserveReferences, _maxItemsInObjectGraph);
innerBehavior.ApplyDispatchBehavior(description, dispatch);
}

public void Validate(OperationDescription description)
{ }
}

public class CustomDataOperationBehavior : DataContractSerializerOperationBehavior
{
private bool _preserveReferences = false;
private int _maxItemsInObjectGraph = 65536;

public CustomDataOperationBehavior(OperationDescription operationDescription, bool preserveReferences, int maxItemsInObjectGraph)
: base(operationDescription)
{
_preserveReferences = preserveReferences;
_maxItemsInObjectGraph = maxItemsInObjectGraph;
}

public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes)
{
return new DataContractSerializer(type, name, ns, knownTypes, this.MaxItemsInObjectGraph, this.IgnoreExtensionDataObject, _preserveReferences, this.DataContractSurrogate);
}

public override XmlObjectSerializer CreateSerializer(Type type, XmlDictionaryString name, XmlDictionaryString ns, IList<Type> knownTypes)
{
return new DataContractSerializer(type, name, ns, knownTypes, _maxItemsInObjectGraph, this.IgnoreExtensionDataObject, _preserveReferences, this.DataContractSurrogate);
}
}
yczf1836 2009-06-30
  • 打赏
  • 举报
回复
不懂,学习一下
破碎的脸 2009-06-30
  • 打赏
  • 举报
回复
WCF........学习了。。。。。暂时没有发言权。。。。
宝_爸 2009-06-30
  • 打赏
  • 举报
回复
看起来是timeout.
NetTcpBinding有几个timeout,你可以选择适当的一个或者全部都设置.
CloseTimeout
OpenTimeout
ReceiveTimeout
SendTimeout

另外搜到一篇文章,看看是不是对你有用.
http://www.cnblogs.com/shanyou/archive/2008/09/22/1296061.html

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧