Question

I'm struggling with setting the OperationTimeout on the RoutingService

The issue is that the service to which the message is forwarded needs more then 1 Minute to give a response. This causes an OperationTimeout Exception on the RoutingService.

I tried to set the OperationTimeout on the client proxy of the RoutingService without success.

What I did, is to add an Endpoint Behavior and add in the ApplyClientBehavior method an custom IClientMessageInspector.

In the custom ClientMessageInspector I set the OperationTimeout, like you see in this code snippet.

    public object BeforeSendRequest(ref Message request, IClientChannel channel)
    {
        var contextChannel = channel as IContextChannel;
        contextChannel.OperationTimeout = new TimeSpan(0, 10, 0);

        return request;
    }

For me it seems that I'm too late at this point and therefore the RoutingService generated proxy doesn't care about this setting, could this be ?

Any suggestions?

Was it helpful?

Solution

I found a solution how to solve this.

You just need to set the SendTimeout on the binding of the client endpoint of the router. When creating the proxy the router will set OperationTimeout=SendTimeout on it's channel.

            // add the endpoint the router uses to receive messages
            serviceHost.AddServiceEndpoint(
                 typeof(IRequestReplyRouter),
                 new BasicHttpBinding(), 
                 "http://localhost:8000/routingservice/router");

            // create the client endpoint the router routes messages to
            var client = new ServiceEndpoint(
                                            ContractDescription.GetContract(typeof(IRequestReplyRouter)), 
                                            new NetTcpBinding(),
                                            new EndpointAddress("net.tcp://localhost:8008/MyBackendService.svc"));

            // Set SendTimeout, this will be used from the router generated proxy as OperationTimeout
            client.Binding.SendTimeout = new TimeSpan(0, 10, 0);

OTHER TIPS

In web.config set SendTimeout in the below

<binding name="myBindingName" sendTimeout="00:10:00"
                 closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" 
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647"
                 crossDomainScriptAccessEnabled="true" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top