tags:

views:

28

answers:

1

Hi

I've got a WCF service which has multiple clients that it connects to.

What I want to do is to create the clients dynamically the WCF services consumes.

Creating the clients by inheriting from the ServiceFactory<TChannel> class is done and very simple. What I'm struggling with is how to read Endpoint behaviours from the web.config file and add them to the clients?

Code file

BasicHttpBinding binding = new BasicHttpBinding(bindingConfigName);
EndpointAddress endpoint = new EndpointAddress(endpointUrl);
ChannelFactory<IShoppingSoap> clientEndpoint = new ChannelFactory<IShoppingSoap>(binding, endpoint);

base.Endpoint.Behaviors.Add(*Get the behavior from the config file*);
return base.CreateChannel();

Web.config file :

<behaviors>  
    <endpointBehaviors>  
       <behavior name="EndpointBehaviour_GmCustom">
         <dataContractSerializer maxItemsInObjectGraph="2147483646" />  
       <behavior>  
    </endpointBehaviors>  
</behaviors>
A: 

Found the solution.. i think.. you have to go through each of the operations in the endpoint and change the maxItemsInObjectGraph there.

foreach (OperationDescription operation in base.Endpoint.Contract.Operations)    
{    
operation.Behaviors.Find<DataContractSerializerOperationBehavior>().MaxItemsInObjectGraph = 2147483646;                    
}

Found the solution here

http://www.lapathy.com/home/2009/9/30/programmatically-setting-maxitemsinobjectgraph-in-wcf.html

Hyder
This does not load the behavior from the config file.
Flo
It allows you to change the config that was read from the config file. I wanted to add this behaviour and change the maxItemsInObjectGraph which i couldn't find unless i read from a config file or performed the logic above.
Hyder