title: Custom .NET Remoting IServerChannelSink
body: <p>i have a client-server application which uses .NET Remoting communication. For authentication reasons i had to write a custom <a href="http://msdn.microsoft.com/en-us/library/8xkh1tek%28v=VS.80%29.aspx" rel="nofollow">IClientChannelSink</a> to insert a session cookie into the HTTP-requests.
  On the server side i also wrote a custom <a href="http://msdn.microsoft.com/en-us/library/t2695x5d%28v=VS.80%29.aspx" rel="nofollow">IServerChannelSink</a> to read some information the server needs from the HTTP-request headers.</p>
  
  <p>The client side works fine, but on the server side i always get the following error:</p>
  
  <blockquote>
    <p>System.ArgumentNullException was unhandled by user code   Message=No
    message was deserialized prior to calling the DispatchChannelSink.
    Parameter name: requestMsg   Source=mscorlib   ParamName=requestMsg<br>
    StackTrace:
           at
    System.Runtime.Remoting.Channels.DispatchChannelSink.ProcessMessage(IServerChannelSinkStack
    sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders,
    Stream requestStream, IMessage&amp; responseMsg, ITransportHeaders&amp;
    responseHeaders, Stream&amp; responseStream)
           at
    MyAuthentication.MyServerChannelSink.ProcessMessage(IServerChannelSinkStack
    sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders,
    Stream requestStream, IMessage&amp; responseMsg, ITransportHeaders&amp;
    responseHeaders, Stream&amp; responseStream) in
    C:\Dev\MyAuthentication\MyServerChannelSink.cs:line 82
           at
    System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack
    sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders,
    Stream requestStream, IMessage&amp; responseMsg, ITransportHeaders&amp;
    responseHeaders, Stream&amp; responseStream)
           at
    System.Runtime.Remoting.Channels.Http.HttpServerTransportSink.ServiceRequest(Object
    state)
           at
    System.Runtime.Remoting.Channels.SocketHandler.ProcessRequestNow()<br>
    InnerException:</p>
  </blockquote>
  
  <p>My "ProcessMessage"-methodlooks as follows:</p>
  
  <pre><code>public ServerProcessing ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, out IMessage responseMsg, out ITransportHeaders responseHeaders, out Stream responseStream)
  {
      // Pre-processing before sending the message to the next sink in the chain
      object state = null;
      ProcessRequest(requestMsg, requestHeaders, ref requestStream, ref state);
  
      /* Call the next sink in the chain */
      sinkStack.Push(this, state);
      ServerProcessing serverProcessing = this.NextChannelSink.ProcessMessage(sinkStack, requestMsg, requestHeaders, requestStream, out responseMsg, out responseHeaders, out responseStream);
  
      // Processing from sink further in the chain has completed. Now do any post-processing before returning to the previous sink in the chain.
      ProcessResponse(null, responseHeaders, ref responseStream, state);
  
      return serverProcessing;
  }
  </code></pre>
  
  <p>Would be great if anyone can tell me whats wrong.</p>