开发者

IPC: WM_COPYDATA + serialization/deserialization

I am currently working on 2 .NET apps which must communicate with each other. Simple Windows Messaging was chosen and this works nicely at the moment. The data that is sent in the messages is a simple string, but now I have created a message class which contains a command (enum) and a data (string) member, and later possible other members.

When I send an instance of such an message class, it is serialized to bytes and then converted to a base64 string. This is then sent out using Windows' SendMessage(). On the other side I do the opposite. Eventually, the original object is restored and available in the other app.

While this mechanism seems to work, I was wondering if this is safe to do. Indeed, there is some overhead, base64 string is much longer than the original string solution (but I would have to parse this tring manually to get command and data part) Is there a maximum size for messages that can be sent with SendMessage ?

Also I'd rather stay away开发者_开发知识库 from .NET remoting for this project and stay with the SendMessage solution.

Any idea's ? Maybe use JSON instead to limit the overhead ?

Thanks.

Pika


Use XDMessaging (http://xdmessaging.codeplex.com/) which supports WM_COPYDATA, Named pipes and IOStream messaging- providing a highly flexible, robust and tested solution, instead of rolling something yourself.

How about using Binary Serialization on your class (http://msdn.microsoft.com/en-us/library/4abbf6k0(v=VS.71).aspx) with XDMessaging? It would be quite compact and very easy to implement.


If you just need to send messages look at a message bus architecture like Rhino Service Bus or NServiceBus. They will provide a relatively simple and much more robust messaging implementation.


I'd really recommend using a more modern, scalable approach. For example, you could easily use named pipes to communicate, and just use standard stream functionality instead of trying to send messages that need to be encoded.

(Personally, I'd probably use WCF, as that has so many benefits, including allowing this to work across different machines for free...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜