Geek Geek - 10 months ago 65
C# Question

WCF Reading Endpoint Behaviors from a web.config file

I've have 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

class is done and very simple. What I'm struggling with is how to read Endpoint behaviours from the
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();

file :

<behavior name="EndpointBehaviour_GmCustom">
<dataContractSerializer maxItemsInObjectGraph="2147483646" />

Answer Source

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