I have a client (and server) with 2 channels set up on different protocols, lets say X:// and Y://.
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://.
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:
RemotingServices.GetObjectData(obj, info, context);
IChannelInfo channelInfo = (IChannelInfo)info.GetValue("channelInfo", typeof(IChannelInfo));
channelInfo.ChannelData = channelInfo.ChannelData.Where(x =>
{
ChannelDataStore ds = x as ChannelDataStore;
if (ds != null)
{
if (!(ds.ChannelUris.Length > 0 && ds.ChannelUris[0].StartsWith("Y://")))
{
return true;
}
else
{
return false;
}
}
return true;
}).ToArray();
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.