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.
Could you not pass in the endpoint to be configured instead?
Also you do not need to pass the argument by ref here.
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);
}
精彩评论