How to add maxItemsInObjectGraph programmatically without using configuration file?

前端 未结 3 2059
陌清茗
陌清茗 2021-02-20 06:39

I have create a EndpointAddress like that

EndpointAddress address = new EndpointAddress(\"http://example.com/services/OrderService.svc\");

But

3条回答
  •  再見小時候
    2021-02-20 07:03

    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(...);
    foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
        {
            var dataContractBehavior = op.Behaviors.Find();
            if (dataContractBehavior != null)
            {
                dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
            }
        }
    

提交回复
热议问题