WCF Client ignores timeout values when service down

Viewed 3911

I have a VB .NET application that uses WCF. I've set the client timeouts for everything in code:

    Dim oMastSrv As MastSvc.IclsIOXferClient = Nothing

    Dim binding As New ServiceModel.NetTcpBinding("NetTcpBinding_IclsIOXfer")
    Dim intTimeout As Integer = 2500
    binding.SendTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
    binding.ReceiveTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
    binding.OpenTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
    binding.CloseTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
    Dim address As New ServiceModel.EndpointAddress("net.tcp://" & GetSrvIP(intSrvID) & ":30000/MyMastSvc")

    oMastSrv = New MastSvc.IclsIOXferClient(binding, address)
    Try
        oMastSrv.ServiceConnect( ... )
        oMastSrv.InnerChannel.OperationTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
    Catch ex As Exception
        ...
    End Try

When the service I'm connected to crashes, though, the Endpoint Not Found exception takes over twenty seconds to be thrown, not the 2.5 I have specified. This is really mucking with my load balancing, I need to know that service is gone within 2.5 seconds. Is there any way to get this exception thrown within the desired time span?

BTW, the exception reads something like:

Could not connect to net.tcp://192.168.227.130:30000/MXIOXfer. The connection attempt lasted for a time span of 00:00:02.4209684. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.227.130:30000.

but it really does take over twenty seconds. I've turned WCF tracing on and can see the TCP operation failed warning just before the exception and it has the REAL time:

Could not connect to net.tcp://192.168.227.130:30000/MXIOXfer. The connection attempt lasted for a time span of 00:00:21.0314092. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.227.130:30000.

If it makes any difference, all the comms to the service are done on separate threads.

EDIT:

This thread seems to indicate that the socket timeouts are set by the operating system. Is there a registry setting for such things?

2 Answers
Related