-
Notifications
You must be signed in to change notification settings - Fork 571
Description
This is not a bug per se but rather an annoying behaviour of the svcutil
tool.
The svcutil
tool generates static methods to get Binding
and EndpointAddress
for a given client (GetBindingForEndpoint
+ GetEndpointAddress
+ optionally GetDefaultBinding
and GetDefaultEndpointAddress
). Unfortunately all those methods are private and as such can't be easily consumed. Here's an example of what is currently generated.
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.HelloEndpointPort))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.HelloEndpointPort))
{
return new System.ServiceModel.EndpointAddress("http://apps.learnwebservices.com/services/hello");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
{
return HelloEndpointClient.GetBindingForEndpoint(EndpointConfiguration.HelloEndpointPort);
}
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
{
return HelloEndpointClient.GetEndpointAddress(EndpointConfiguration.HelloEndpointPort);
}
public enum EndpointConfiguration
{
HelloEndpointPort,
}
Let's say you want to tweak the default binding to change some timeouts (and possible some other settings). This is currently impossible to do because the generated methods are private.
var binding = HelloEndpointClient.GetDefaultBinding();
binding.OpenTimeout = TimeSpan.FromSeconds(5);
binding.CloseTimeout = TimeSpan.FromSeconds(6);
binding.SendTimeout = TimeSpan.FromSeconds(7);
binding.ReceiveTimeout = TimeSpan.FromSeconds(8);
await using var client = new HelloEndpointClient(binding, HelloEndpointClient.GetDefaultEndpointAddress());
The contents of those generated methods must be duplicated when it needs to be tweaked.
Making those static methods public instead private would solve this issue.