none
Getting rid of tcp channel error RRS feed

  • Question

  • I've a .Net client/server app in which am using tcp binding to communicate with the WCF service. If the client is idle for say about an hour or so and if it then re-invokes a method on the server, the client keeps throws following error:

    System.ServiceModel.ProtocolException: This channel can no longer be used to send messages as the output session was auto-closed due to a server-initiated shutdown. Either disable auto-close by setting the DispatchRuntime.AutomaticInputSessionShutdown to false, or consider modifying the shutdown protocol with the remote server.

    To get rid of this, I need to restart the client or the server as a quick fix.

    For a longterm solution, am I supposed to use reliableSession in both client and server with timeout as say 20 hours?

    <reliableSession enabled="true" inactivityTimeout="00:20:00" />

    client:

     <system.serviceModel>
            <bindings>
              <netTcpBinding>
                <binding name="NetTcpBinding_ITestInterface" />
              </netTcpBinding>
            </bindings>
            <client>
              <endpoint address="net.tcp://localhost:8733/MyService.ITestInterface/MyService/" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_MyService" contract="MyService.TestInterface" name="NetTcpBinding_ITestInterface">
                <identity>
                  <dns value="localhost" />
                </identity>
    
              </endpoint>
            </client>
          </system.serviceModel>

    server:

     <system.serviceModel>
        <bindings>
          <netTcpBinding>
            <binding name="NetTcpBinding_ITestInterface">
              <security mode="None" />
            </binding>
        </bindings>
    
      </system.serviceModel>

    Or do I need to use DuplexChannelFactory when creating a proxy at the client side?

    var proxy = new DuplexChannelFactory<AlarmServer>(context,
                                       "NetTcpBinding_ITestInterface").CreateChannel()

    Or is there any other more efficient way of getting rid of this error?

    https://www.amazon.com/returns/label/de91cb0c-2e5c-45ec-ba1d-c5cb1dac6f57/rmaID/D230RHqsRRMA?ref_=pe_584750_33951330_orc_label_share_url_page&token=N%2FLBJ.cFV53JPu3wRVnfO8y2QZ%2FupDdD1DmcLZNsMAM0vpJAIaI2YRAO1u8sLHzuc0DROxWepKF9C3C16qh3dDLBooubnBQ2mLAcxb5d9SL5U5
    • Edited by ANi2000 Monday, September 25, 2017 2:11 AM
    Thursday, September 15, 2016 6:57 PM

All replies

  • Hi Ani2000,

    >> I supposed to use reliableSession in both client and server with timeout as say 20 hours?

    If your session is more than an hour, I think you need to set inactivityTimeout as “02:00:00”. It indicates timeout is 2hs, "00:20:00" is 20 minutes.

    Based on the error message, it seems you could set DispatchRuntime.AutomaticInputSessionShutdown to false, for this, I suggest you try

                ServiceHost host = new ServiceHost(typeof(Service1));
                foreach (ChannelDispatcher channelDipsatcher in host.ChannelDispatchers)
                {
                    foreach (EndpointDispatcher endpointDispatcher in channelDipsatcher.Endpoints)
                    {                 
    
                        endpointDispatcher.DispatchRuntime.AutomaticInputSessionShutdown = false;
                    }
                }
    
                host.Open();
    

    Based on my researching, it seems if a WCF Server encounters an exception that is not being caught and handled, it will “fault” the channel, and rendering it useless. For this kind issue, you need to through FaultException instead of Exception. You could refer the link below for more information.

    # Dealing with WCF service restart on client-side

    http://stackoverflow.com/questions/1985225/dealing-with-wcf-service-restart-on-client-side

    In attrition, I would suggest you Configure Tracing to check the real error.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, September 16, 2016 4:24 AM
  • Thanks for your response Edward.But host.ChannelDispatchers collection count is zero in my case.What am I missing please?

    • Edited by ANi2000 Friday, September 16, 2016 6:33 PM
    Friday, September 16, 2016 6:29 PM
  • Hi ANI,

    It seems we need to add ChannelDispatcher first, you could refer WCF Extensibility – IServiceBehavior. Since there is no ChannelDispatcher in your scenario, I would suggest you try other methods first.

    Have you tried Dealing with WCF service restart on client-side and inactivityTimeout? Did you check the error log in Configure Tracing.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, September 19, 2016 6:58 AM
  • Ok.Will try the same then.Thanks Edward for your inputs.
    Friday, September 23, 2016 8:49 PM
  • Hi ANi,

    Have your issue been resolved? If you have any updates about your issue, please feel free to let us know.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, September 30, 2016 5:37 AM