WCF basicHttpBinding Client does not close socket connection even after calling Close()

201 Views Asked by At

My solution is implementing ServiceProxyClient using .NET Framework 4.6. I could call the remote method and client opens a connection to remote server in specified port. But WCF does not close the socket connection explicitly. I have tried to catch all exceptions and call Abort() in catch block. But the service does not throw any exception. Client waits as the earlier socket connection opened by client is still in use and I am getting timeout error after 3 -4 minutes.

Here is sample code

var client = new ServiceClient();
try 
{
  var response = client.SomeMethod(parmater);
  client.ChannelFactory.Close();
  client.Close();

 }
 catch (FaultException)
 {
     client.Abort();
 }
 catch (CommunicationException)
 {
     client.Abort();
 }
 catch(Exception)
 {
      client.Abort();
 }

Calling Close() and Abort() does not seem to close socket connection open to remote server.

I have generated serviceproxy references using VS2017. Using basichttpbinding for remote endpoint.

<basicHttpBinding>
    <binding name="HttpService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    </binding>

Do we have any ways to close the socket connection to remote server from client side ?

0

There are 0 best solutions below