通过网络传递消息
我目前正在尝试开发一个面向消息的网络框架,但我对内部机制有点困惑。
以下是有问题的接口:
public interface IMessage
{
}
public class Connection
{
public void Subscribe<TMessage>(Action<TMessage> messageCallback);
public void Send<TMessage>(TMessage message);
}
Send
方法看起来并不复杂,尽管 Subscribe
背后的机制似乎有点痛苦。 显然,当在连接的一端收到消息时,我必须调用适当的委托。 您对如何阅读消息并轻松检测其类型有什么建议吗?
顺便说一句,我想避免使用 MSMQ。
I'm currently trying to develop a message-oriented networking framework and I'm a bit stuck on the internal mechanism.
Here are the problematic interfaces :
public interface IMessage
{
}
public class Connection
{
public void Subscribe<TMessage>(Action<TMessage> messageCallback);
public void Send<TMessage>(TMessage message);
}
The Send
method does not seem complicated, though the mechanism behind Subscribe
seems a bit more painful.
Obviously when receiving a message on one end of the connection, I'll have to invoke the appropriate delegate.
Do you have any advice on how to read messages and easily detect their types ?
By the way, I'd like to avoid to use MSMQ.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来 Windows Communication Foundation 的创建就是为了解决这个问题: http://msdn. microsoft.com/en-us/netframework/aa663324.aspx,但您已将问题标记为 .NET 2.0,因此这可能不适合您。
相反,如果您同时控制客户端和服务器端,请查看 .NET Remoting:http://msdn.microsoft.com/en-us/library/kwdt6w2k(VS.71).aspx。
Sounds like a problem Windows Communication Foundation was created to solve: http://msdn.microsoft.com/en-us/netframework/aa663324.aspx but you've tagged the question .NET 2.0 so that may not be an option for you.
Instead, if you're in control of both the client and server sides, take a look at .NET Remoting: http://msdn.microsoft.com/en-us/library/kwdt6w2k(VS.71).aspx.