当前位置: 首页 > 编程语言 > C#

如何在不使用配置文件的情况下以编程方式添加maxItemsInObjectGraph?Share

时间:2023-04-11 11:56:14 C#

如何在不使用配置文件的情况下以编程方式添加maxItemsInObjectGraph?我创建了类似EndpointAddressEndpointAddressaddress=newEndpointAddress("http://example.com/services/OrderService.svc");但我无法以编程方式将此行为添加到此端点。行为如下:在服务器上,您必须将此添加到ServiceBehavior属性:[ServiceBehavior(MaxItemsInObjectGraph=int.MaxValue)]在客户端上,您必须将此应用到端点。在此示例中,您可以看到如何将其添加到ChannelFactory中的所有端点:varfactory=newChannelFactory(...);foreach(OperationDescriptionopinfactory.Endpoint.Contract.Operations){vardataContractBehavior=op.行为.Find();if(dataContractBehavior!=null){dataContractBehavior.MaxItemsInObjectGraph=int.MaxValue;在服务器端你也可以:ServiceHosthost=newServiceHost();ServiceBehaviorAttributesba=host.Description.Behaviors.Find();if(sba==null){sba=newServiceBehaviorAttribute();sba.MaxItemsInObjectGraph=int.MaxValue;host.Description.Behaviors.Add(sba);替代方法:((ServiceBehaviorAttribute)host.Description.Behaviors[typeof(ServiceBehaviorAttribute)]).MaxItemsInObjectGraph=int.MaxValue;以上是C#学习教程:HowtoprogrammaticallyaddmaxItemsInObjectGraphwithoutusingaconfigurationfile?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: