title: How do you specify the channel .NET remoting will use to perform a callback
body: <p>I have a client (and server) with 2 channels set up on different protocols, lets say X:// and Y://.</p>
  
  <p>If I call a service (over remoting) from client (C) on a server (S) that needs to perform a callback to the client (so S->C) is there a way to specify which channel to use?  In my use case I want any calls from X:// to callback over X:// and any calls over Y:// to callback over Y://.</p>
  
  <p>My current solution is to implement a custom serialization surrogate (and selector) for each channel for MarshalByRefObjects that removes the URI of the other channel from the SerializationInfo when serializing them.  Similar to:</p>
  
  <pre><code>            RemotingServices.GetObjectData(obj, info, context);
              IChannelInfo channelInfo = (IChannelInfo)info.GetValue("channelInfo", typeof(IChannelInfo));
              channelInfo.ChannelData = channelInfo.ChannelData.Where(x =&gt;
              {
                  ChannelDataStore ds = x as ChannelDataStore;
                  if (ds != null)
                  {
                      if (!(ds.ChannelUris.Length &gt; 0 &amp;&amp; ds.ChannelUris[0].StartsWith("Y://")))
                      {
                          return true;
                      }
                      else
                      {
                          return false;
                      }
                  }
                  return true;
              }).ToArray();
  </code></pre>
  
  <p>This actually works but just feels wrong (ex: relying on "channelInfo" string in the populated SerializationInfo).  Does anyone know of a better solution?  I've looked pretty throughly through RemotingServices.GetObjectData but still couldn't figure out where it gets the URI list from.</p>