如何指定 .NET 远程处理用于执行回调的通道
我有一个客户端(和服务器),有两个在不同协议上设置的通道,比如说 X:// 和 Y://。
如果我从服务器 (S) 上的客户端 (C) 调用一个服务(通过远程处理),该服务需要对客户端执行回调(因此 S->C),有没有办法指定要使用哪个通道?在我的用例中,我希望来自 X:// 的任何调用都通过 X:// 回调,并且通过 Y:// 的任何调用都通过 Y:// 回调。
我当前的解决方案是为 MarshalByRefObjects 的每个通道实现自定义序列化代理(和选择器),在序列化它们时从 SerializationInfo 中删除其他通道的 URI。类似于:
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();
这实际上有效,但感觉不对(例如:依赖于填充的 SerializationInfo 中的“channelInfo”字符串)。有谁知道更好的解决方案?我已经彻底查看了 RemotingServices.GetObjectData,但仍然无法弄清楚它从哪里获取 URI 列表。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论