I have a WCF service using wsHttpBinding with message encryption. I use the same service reference unless it has become faulted, in which case I create a new one. I'm running in to an issue where the session has timed out and the service has closed its end, but the client application still has the CommunicationState as Opened.
How can I tell in ClientBase if the connection has timed out? I want in my client application to create a new service proxy if the current one has timed out.
Below is my client-side binding:
<wsHttpBinding>
<binding name="wsHttpBindingWithAuthClient" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="20000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
Why don't you just wrap all of your service calls in a try/catch, and in the catch block of the specific exception type of server connection timeout, recreate the proxy.
try
{
serviceProxyGlobal.Method()
}
catch(WhateverServerTimeoutException ex)
{
serviceProxyGlobal = new ServiceProxy();
//retry maybe?
}
catch(Exception ex)
{
logException(ex);
}