如何在不使用配置文件的情况下以编程方式添加 maxItemsInObjectGraph?
我已经创建了一个像这样的 EndpointAddress
EndpointAddress address = new EndpointAddress("http://example.com/services/OrderService.svc");
但我无法以编程方式将行为添加到该端点。
该行为如下:
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600" />
</behavior>
</endpointBehaviors>
</behaviors>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在服务器上,您必须将其添加到 ServiceBehavior 属性中:
在客户端上,您必须将其应用到端点。在此示例中,您可以看到如何将其添加到 ChannelFactory 中的所有端点:
On the server you have to add it in the ServiceBehavior Attribute:
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:
在服务器端,您还可以:
On Server Side, you can also:
替代方案:
((ServiceBehaviorAttribute) host.Description.Behaviors[typeof(ServiceBehaviorAttribute)]).MaxItemsInObjectGraph = int.MaxValue;
Alternative:
((ServiceBehaviorAttribute) host.Description.Behaviors[typeof(ServiceBehaviorAttribute)]).MaxItemsInObjectGraph = int.MaxValue;