Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting OperationTimeout on Wcf RoutingService

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?

like image 966
Giulia Amato Avatar asked Jan 21 '26 11:01

Giulia Amato


1 Answers

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);
like image 153
Giulia Amato Avatar answered Jan 24 '26 16:01

Giulia Amato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!