2

The error message is following:

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.

It happens, when I create a web request to a WCF router (wsHttpBinding or BasicHttpBinding to NetTcpBinding) and the router then requests WinService. Once the WinService throws an Exception, the next requests gives the error message above. It is created by the WCF router. There was no solution anywhere, I've spend days finding one.

Links to similar problems without solution:

Community
  • 1
  • 1
Jan Matousek
  • 956
  • 3
  • 13
  • 15

1 Answers1

2

The working solution I did is following:

  • Do not throw an Exception, throw FaultException

How to do that:

  • On the WinService interface define a response code enum (example following)
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "blah")]
public enum ErrorCode
{
    ERROR
}

or just

public enum ErrorCode
{
    ERROR
}
  • then instead of an Exception throw FaultException using defined enum:

throw new FaultException(ErrorCode.ERROR, new FaultReason("blah"), new FaultCode("Sender"));

  • And that's it! Now you can send request that generate this exception and it doesn't close the channel
Jan Matousek
  • 956
  • 3
  • 13
  • 15