Reputation: 9222
I am not quite sure if I am testing these correctly, but I am trying to determine the impact of one of the Timeouts for (Close,Receive,Send,Open) for the binding on the service.
I am programatically setting the values because I prefer it over configuration based so please dont recommend me putting it back in the config file.
To test the extreme, I am attempting to set the Timeout to 1 second so that it should hit no matter what.
I am not sure however that this is the case
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
ServiceThrottlingBehavior behavior = new ServiceThrottlingBehavior();
behavior.MaxConcurrentCalls = 1000;
behavior.MaxConcurrentInstances = 1000;
behavior.MaxConcurrentSessions = 1000;
serviceDescription.Behaviors.Add(behavior);
foreach (var endpoint in serviceDescription.Endpoints)
{
var binding = endpoint.Binding;
binding.CloseTimeout = TimeSpan.FromSeconds(1);
binding.ReceiveTimeout = TimeSpan.FromSeconds(1);
binding.SendTimeout = TimeSpan.FromSeconds(1);
binding.OpenTimeout = TimeSpan.FromSeconds(1);
endpoint.Binding = binding;
}
foreach (ChannelDispatcher cd in serviceHostBase.ChannelDispatchers)
{
foreach (EndpointDispatcher ed in cd.Endpoints)
{
if (!ed.IsSystemEndpoint)
{
ed.DispatchRuntime.InstanceProvider = new MyProvider(serviceDescription.ServiceType)
}
}
}
}
I have tracing enabled as well and have been trying to monitor it to see if anything has changed, but nothing has caught my eye.
Upvotes: 0
Views: 374
Reputation: 12135
Did you read this note in the MSDN API documentation for ApplyDispatchBehavior
?
All of the IServiceBehavior methods pass System.ServiceModel.Description.ServiceDescription and System.ServiceModel.ServiceHostBase objects as a parameters. The ServiceDescription parameter is for examination and insertion of customizations only; if you otherwise modify these objects the execution behavior is undefined.
The ServiceDescription
and Binding
object are not part of the runtime channel stack, but rather are used just to determine how the runtime should be built when the ServiceHost
is opened and the channel listener first created.
Your service behavior's ApplyDispatchBehavior
is called during initialisation of the channel listener and runtime channel stack, too late for your changes to the timeout properties of the Binding object itself to have any effect on the channel run time being built.
You may have more luck if you set these properties in AddBindingParameters
instead, as that method is called earlier in the process of building the runtime but even though that might work, it's still undefined behavior.
Really, though, these properties should be set on the Binding before the ServiceHost
is opened.
Upvotes: 1