简体   繁体   English

在Wcf RoutingService上设置OperationTimeout

[英]Setting OperationTimeout on Wcf RoutingService

I'm struggling with setting the OperationTimeout on the RoutingService 我正在努力在RoutingService上设置OperationTimeout

The issue is that the service to which the message is forwarded needs more then 1 Minute to give a response. 问题是转发消息的服务需要超过1分钟才能给出响应。 This causes an OperationTimeout Exception on the RoutingService. 这会导致RoutingService上的OperationTimeout异常。

I tried to set the OperationTimeout on the client proxy of the RoutingService without success. 我试图在RoutingService的客户端代理上设置OperationTimeout但没有成功。

What I did, is to add an Endpoint Behavior and add in the ApplyClientBehavior method an custom IClientMessageInspector. 我所做的是添加一个Endpoint Behavior并在ApplyClientBehavior方法中添加一个自定义IClientMessageInspector。

In the custom ClientMessageInspector I set the OperationTimeout, like you see in this code snippet. 在自定义ClientMessageInspector中,我设置了OperationTimeout,就像您在此代码段中看到的那样。

    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 ? 对我来说,似乎我现在已经太迟了,因此RoutingService生成的代理不关心这个设置,这可能是吗?

Any suggestions? 有什么建议么?

In web.config set SendTimeout in the below 在web.config中设置下面的SendTimeout

<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" />

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. 您只需要在路由器的客户端端点的绑定上设置SendTimeout。 When creating the proxy the router will set OperationTimeout=SendTimeout on it's channel. 创建代理时,路由器将在其通道上设置OperationTimeout = SendTimeout。

            // 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM