簡體   English   中英

在Wcf RoutingService上設置OperationTimeout

[英]Setting OperationTimeout on Wcf RoutingService

我正在努力在RoutingService上設置OperationTimeout

問題是轉發消息的服務需要超過1分鍾才能給出響應。 這會導致RoutingService上的OperationTimeout異常。

我試圖在RoutingService的客戶端代理上設置OperationTimeout但沒有成功。

我所做的是添加一個Endpoint Behavior並在ApplyClientBehavior方法中添加一個自定義IClientMessageInspector。

在自定義ClientMessageInspector中,我設置了OperationTimeout,就像您在此代碼段中看到的那樣。

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

        return request;
    }

對我來說,似乎我現在已經太遲了,因此RoutingService生成的代理不關心這個設置,這可能是嗎?

有什么建議么?

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

我找到了解決方案如何解決這個問題。

您只需要在路由器的客戶端端點的綁定上設置SendTimeout。 創建代理時,路由器將在其通道上設置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