本文介绍了如何添加maxItemsInObjectGraph编程,而无需使用配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已创建一个这样的的EndpointAddress
的EndpointAddress地址=新的EndpointAddress(http://example.com/services/OrderService.svc);
但我不能添加行为到这个端点编程。
的行为如下:
<行为>
< endpointBehaviors>
<行为NAME =NewBehavior>
< DataContractSerializer的maxItemsInObjectGraph =6553600/>
< /行为>
< / endpointBehaviors>
< /行为>
解决方案
在服务器上,您必须将其添加在ServiceBehavior属性:
[ServiceBehavior(MaxItemsInObjectGraph = int.MaxValue)
在客户端,你必须将其应用到端点。在这个例子中,你可以看到如何将它添加到所有终端在你的ChannelFactory:
VAR厂=新的ChannelFactory< IInterface>(...);
的foreach(OperationDescription运在factory.Endpoint.Contract.Operations)
{
变种dataContractBehavior = op.Behaviors.Find&其中; DataContractSerializerOperationBehavior>();
如果(dataContractBehavior!= NULL)
{
dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
}
}
I have create a EndpointAddress like that
EndpointAddress address = new EndpointAddress("http://example.com/services/OrderService.svc");
But I could not add the Behavior to this Endpoint programmatically.
The behavior is given below.:
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600" />
</behavior>
</endpointBehaviors>
</behaviors>
解决方案
On the server you have to add it in the ServiceBehavior Attribute:
[ServiceBehavior(MaxItemsInObjectGraph = int.MaxValue)]
On the client you have to apply it to the endpoint. In this example you can see how to add it to all the endpoints in your ChannelFactory:
var factory = new ChannelFactory<IInterface>(...);
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
var dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>();
if (dataContractBehavior != null)
{
dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
}
}
这篇关于如何添加maxItemsInObjectGraph编程,而无需使用配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!