【问题标题】:Setting OperationTimeout on Wcf RoutingService在 Wcf RoutingService 上设置 OperationTimeout
【发布时间】:2015-04-30 01:47:24
【问题描述】:

我正在努力在 RoutingService 上设置 OperationTimeout

问题是消息转发到的服务需要超过 1 分钟才能做出响应。这会导致 RoutingService 出现 OperationTimeout 异常。

我尝试在 RoutingService 的客户端代理上设置 OperationTimeout,但没有成功。

我所做的是添加一个 Endpoint Behavior 并在 ApplyClientBehavior 方法中添加一个自定义 IClientMessageInspector。

在自定义 ClientMessageInspector 中,我设置了 OperationTimeout,就像您在这段代码 sn-p 中看到的那样。

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

        return request;
    }

对我来说,此时我似乎为时已晚,因此 RoutingService 生成的代理并不关心此设置,可能是这样吗?

有什么建议吗?

【问题讨论】:

  • 您不需要在帖子中包含签名 - 您的用户卡会自动添加。阅读FAQ了解更多详情。
  • 好的,谢谢,没意识到。

标签: c# .net wcf wcf-routing


【解决方案1】:

我找到了解决方法。

您只需要在路由器的客户端端点绑定上设置 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);

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 我对这篇文章投了反对票,因为虽然它有效,但它非常不精确。有关客户端使用的超时的详细信息,请参阅stackoverflow.com/a/5310933/249742:在这种情况下,唯一要更改的超时是 sendTimeout。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多