如何在.NET远程使用自定义序列化? [英] How to use custom serialization during .NET remoting?

查看:113
本文介绍了如何在.NET远程使用自定义序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写不使用ISerializable的或SerialzableAttribute我的对象保存到一个文件中的自定义序列化程序。

I've written a custom serialization routine that does not use ISerializable or the SerialzableAttribute to save my objects to a file.

我也遥控这些相同的对象,并想用相同的序列化技术。不过,我不希望实现ISerializable的,因为我的序列化方法是完全从我的对象解耦(我想让它保持这种方式)。

I also remote these same objects and would like to use the same serialization technique. However, I don't want to implement ISerializable because my serialization method is completely decoupled from my objects (and I'd like for it to stay that way).

有没有一种简单的方法(可能与远程处理水槽),在那里我可以一个流写字节,并在另一边从中读取字节,跳过了序列化框架.NET?

Is there an easy way (possibly with remoting sinks) where I can take a stream and write bytes to it and on the other side read bytes from it, skipping the Serialization framework in .NET?

推荐答案

如果你想使用的远程的则是有限的的BinaryFormatter 。通常情况下,你可以使用一个序列化替代提供了串行分离到格式,但AFAIK使用.NET远程处理这个deoesn't的工作。

If you want to use remoting then you are limited to BinaryFormatter. Normally, you can use a "serialization surrogate" to provide a serializer separate to the formatter, but AFAIK this deoesn't work with .NET remoting.

不过,如果你写你自己的RPC堆栈(通过TCP / IP或HTTP等),你就会有更多的控制。同样,与WCF,你可以通过行为取代串行。我在 protobuf网(WCF的挂钩使用这两种招数< A HREF =HTTP://$c$c.google.com/p/protobuf-net/source/browse/#svn/trunk/protobuf-net/ServiceModel相对=nofollow>在这里 )。

However; if you write your own RPC stack (over TCP/IP or HTTP, for example), you'll have a lot more control. Equally, with WCF you can replace the serializer via a behavior. I use both of these tricks in protobuf-net (the WCF hooks are here).

不知道你可以做到这一点的远程的不过 - 你可能需要使用 ISerializable的

Not sure you can do this with remoting though - you'd probably have to use ISerializable.

这篇关于如何在.NET远程使用自定义序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆