set maxItemsInObjectGraph in client config [from Stackflow]

I am specifying maxItemsInObjectGraph in the server config file but while creating client config file, this attribute is ignored and i have to manually add it in the endpointBehaviors section.

Is there a way i can make some changes in the config file so that everytime i generate client config and proxy via Svcutil.exe, this behaviour is automatically included in the client config file?

i tried ading [ServiceBehavior(MaxItemsInObjectGraph = 2147483647)] to the service interface but it gives me an error saying Attribute 'ServiceBehavior' is not valid on this declaration type. It is only valid on 'class' declarations.

 

 

No, that is another behavior which is configured per participant. Each client has control over this property and service doesn't expose this property because it could be considered as security issue.

If your problem is mainly about development (where you don't want to modify your behavior every time you refresh the reference) you can use commonBehaviors section which can be defined only in machine.config:

<commonBehaviors> 
  <behaviors> 
    <endpointBehaviors> 
      <dataContractSerializer maxItemsInObjectGraph="..." /> 
    </endpointBehaviors> 
  </behaviors> 
</commonBehaviors> 

Common behaviors are added to every service / endpoint running on the machine. It is perhaps good for development but you mustn't forget that once you will prepare package for production you will have to add this configuration to production's config file - because of that it is better to maintain such configuration file continuously and use it on some build / test server.

 

 

 

 

Behaviors are typically local settings (you can have different values for client and server, and the communication can still work out fine), so they're not exposed in WSDL (and so svcutil will not be able to find that value).

You have basically 2 choices: update the client config every time you generate, or in code, when you create an instance of the proxy class, update the MIIOG property, similar to the code below.

ServiceClient client = new ServiceClient(); 
foreach (var operationDescription in client.Endpoint.Contract.Operations) 
{ 
    DataContractSerializerOperationBehavior dcsob = 
        operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>(); 
    if (dcsob != null) 
    { 
        dcsob.MaxItemsInObjectGraph = int.MaxValue; 
    } 
} 

Note that if you are handwriting the client implementation instead of using auto-generated stubs, the Endpoint is available through the ChannelFactory used to create the channel for the service interface

 

From: http://stackoverflow.com/questions/6283037/set-maxitemsinobjectgraph-in-client-config

转载于:https://www.cnblogs.com/anorthwolf/archive/2012/08/30/2664294.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值