简体   繁体   English

如何检查 WCF 客户端通道(服务)是否终止?

[英]How to check if WCF client channel (service) terminated or not?

I have simple WCF service hosted on Windows Service.我在 Windows 服务上托管了简单的 WCF 服务。

When the client of wcf service is idle for 10 minutes or more WCF service terminated at client side [ not at server side, server service is still alive] and i got famaous time out error.当 wcf 服务的客户端空闲 10 分钟或更长时间时,WCF 服务在客户端终止[不在服务器端,服务器服务仍然存在],我得到了著名的超时错误。

I do not want to increase timeout time.我不想增加超时时间。 I just wanted to know is there is an elagant way to know if a service is terminated or not at client side?[ Does API provides this info?] Then If session terminated i will create new one.我只是想知道是否有一种优雅的方法可以知道服务是否在客户端终止?[ API 是否提供此信息?] 那么如果 session 终止,我将创建新的。

Best Wishes最好的祝愿

Ps: At client side i checked WCFClientChannel->Sate == CommunicationState::Faulted and this does not worked Ps:在客户端我检查了WCFClientChannel->Sate == CommunicationState::Faulted但这不起作用

Unfortunately the only way to know that a proxy is no longer usable is to attempt to use it.不幸的是,知道代理不再可用的唯一方法是尝试使用它。

What's actually happening is you are using a binding which is sessionful (say NetTcpBinding or WSHttpBinding) for which the service maintains resources for the client connection.实际发生的情况是您使用的是会话绑定(例如 NetTcpBinding 或 WSHttpBinding),服务为其维护客户端连接的资源。 If the client doesn't talk to the service for the amount of time specified in the service's receiveTimeout (default 10 minutes) then the server decides the client isn't coming back and throws away the client's server side resources.如果客户端在服务的 receiveTimeout 中指定的时间(默认为 10 分钟)内没有与服务通信,则服务器决定客户端不会回来并丢弃客户端的服务器端资源。

Now when the client comes back and says "hey its me again" the server says "I have no idea what you're talking about" and faults the call thus killing the clients proxy现在,当客户端回来说“嘿,又是我”时,服务器会说“我不知道你在说什么”并导致调用出错,从而杀死客户端代理

Therefore, as the decision has been taken server side, there is no way the client will know unless it tries to talk to the service因此,由于决定是在服务器端做出的,除非客户端尝试与服务对话,否则客户端无法知道

You could do one of the following:您可以执行以下操作之一:

  1. increase the receiveTimeout on the server (but that just makes it take longer to see the problem)增加服务器上的receiveTimeout(但这只会增加查看问题的时间)
  2. use a binding that is not sessionful (say BasicHttpBinding)使用非会话绑定(比如 BasicHttpBinding)
  3. have a "ping" operation that gets called by the client every few minutes to let the service know its still there有一个“ping”操作,客户端每隔几分钟就会调用一次,让服务知道它仍然存在

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

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