How to check if WCF client channel (service) terminated or not?
I have simple WCF service hosted on Windows Service.
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.
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.
Best Wishes
Ps: At client side i checked WCFClientChannel->Sate == CommunicationState::Faulted
and this does not worked
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. 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.
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:
- increase the receiveTimeout on the server (but that just makes it take longer to see the problem)
- use a binding that is not sessionful (say BasicHttpBinding)
- have a "ping" operation that gets called by the client every few minutes to let the service know its still there
精彩评论