none
TCP socket closing with use of custom IErrorHandler Extension? RRS feed

  • Question

  • I have spent all day trying to solve a very strange issue with no success. Perhaps someone here can enlighten me?  I am using net.tcp binding to connect to a service. nothing complicated.. we are caching the proxy so that multiple people can use it. Also, to make it so that I didn't have to worry about handling all unknown exceptions up front. we built a custom Error Handler extension that plugs into the service and calls ProvideFault to wrap all unhandled exceptions into a fault exception. So here's the thing...


    I have a simple test where the client connects to the service using net.tcp, makes 2 service calls in succession, and then exits... this client is a self hosted app. The service is also running in a console application host.  When debugging the client.. the data is coming back fine from the service on both calls.. no problems whatsoever..  now here's where things get wierd..  so.. when the client has nothing else to run in the main method.. it exits.. and as soon as it does... the service throws up and closes with some exception about the socket being forcibly closed due to a callback. 

     

    When I debug.. I see that the service methods are being called fine.. and then once the client app terminates.. I see the service go into the error handler I wrote and try to throw this exception.  Here are some other things I found out:

     

    Changing the binding to WsHttp fixes the issue. Also, removing the custom error handler so that there are no custom error behaviors works with net.tcp

     

    I know that tcp binding is sessionful and supports duplex communication but is there something about those properties of this connection that make it so that this happens?  I appreciate any thoughts anyone has on this.

     

    --D

    Saturday, April 19, 2008 3:24 AM

Answers

  • I think it happens because the channel isn't being closed explicitly when the client code exits.  Try adding something like:

    ((IChannel)client).Close().

     

    If this doesn't work, can you post your code for this?

     

    -James

     

    Wednesday, April 30, 2008 10:49 PM
    Moderator