我正在努力设置 RoutingService 上的 OperationTimeout|
问题是消息转发到的服务需要超过 1 分钟的时间才能做出响应。这会导致 RoutingService 出现 OperationTimeout 异常。
我尝试在 RoutingService 的客户端代理上设置 OperationTimeout 但没有成功。
我所做的是添加端点行为并在 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 生成的代理不关心这个设置,这可能是吗?
有什么建议吗?
最佳答案
我找到了解决这个问题的方法。
您只需要在路由器的客户端端点的绑定(bind)上设置 SendTimeout。创建代理时,路由器将在其 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);
关于c# - 在 Wcf RoutingService 上设置 OperationTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13915623/