When authoring a session-ful channel, it’s important to signal “end of session” correctly so that the runtime (or any other user of the channel) knows when to stop reading messages, and to start shutting down his side of the conversation (with CloseOutputSession and/or channel.Close). A null
Message/RequestContext signals end-of-session to the caller. In particular, depending on your channel shape, you should do the following:
- IInputSessionChannel/IDuplexSessionChannel: Return
null
from channel.Receive(). Correspondingly, returntrue
from TryReceive with the “message” out-param set tonull
. And of course, cover your bases by having BeginTryReceive complete synchronously with a signal to returntrue
+ message =null
from EndTryReceive. - IRequestSessionChannel: Return
null
from channel.ReceiveRequest(). Correspondingly, returntrue
from TryReceiveRequest with the “context” out-param set tonull
. Lastly, have BeginTryReceiveRequest complete synchronously with a signal to returntrue
+ context =null
from EndTryReceiveRequest.