tags:

views:

298

answers:

3

I have a few WCF services I am calling from a console app.

I have methods for setting the binding timeout programatically like this:

 private static void InitRepClient(ref Reporting.ReportingClient rc)
        {
            rc.Endpoint.Binding.CloseTimeout = new TimeSpan(12, 0, 0);
            rc.Endpoint.Binding.ReceiveTimeout = new TimeSpan(12, 0, 0);
            rc.Endpoint.Binding.SendTimeout = new TimeSpan(12, 0, 0);
            rc.Endpoint.Binding.OpenTimeout = new TimeSpan(12, 0, 0);
        }

I want to instead change the input parameter to accept any WCF service. So that I don't have to have 1 function for each service. Of what class type should my input parameter be?

Thanks in advance.

+1  A: 

The base type of the client proxies is a generic type ClientBase<T>. This means that you would need to make your method generic, like this:

private static void InitClient<T>(ClientBase<T> client) where T : class
{ 
   client.Endpoint.Binding.CloseTimeout = new TimeSpan(12, 0, 0); 
   client.Endpoint.Binding.ReceiveTimeout = new TimeSpan(12, 0, 0); 
   client.Endpoint.Binding.SendTimeout = new TimeSpan(12, 0, 0); 
   client.Endpoint.Binding.OpenTimeout = new TimeSpan(12, 0, 0); 
}
Samuel Jack
+2  A: 

Could you not pass in the endpoint to be configured instead?

Also you do not need to pass the argument by ref here.

Rune Grimstad
A: 

Also you do not need to pass the argument by ref here.

Can you elaborate on why you do not need to pass the arg by ref?

thewizster