爪哇 - .NET对象交换,而不是基于Web的 [英] Java - .Net object interchange, not web-based

查看:204
本文介绍了爪哇 - .NET对象交换,而不是基于Web的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#实现客户端 - 服务器系统,并通过序列化/反序列化的客户端和服务器交换.NET对象,并通过TCP / IP通信。这将运行在本地网络上,它不是基于网络或基于因特网的

I have a client-server system implemented in C#, and the client and server exchange .Net objects via serialization / deserialization and communicating via TCP/IP. This runs on a local network, it is not web-based or Internet-based.

现在我想包括通过无线连接的Andr​​oid客户端。再次,这是本地网络只,不经​​由互联网,而不是基于网络的。而Android编程将使用Java语言。 (我知道单声道为Android,但preFER不进入现在。)

Now I want to include Android clients connected by wifi. Again, this is local network only, not via the Internet and not web-based. The Android programming will be in Java. (I am aware of Mono for Android, but prefer not to get into that now.)

有一些实现对象Java和.NET对象之间的对象交换,前提当然是相当简单的方式,他们是兼容的?

Is there some fairly simple way to implement object to object interchange between Java and .Net objects, provided, of course, that they are compatible?

我查了一下,在JSON(杰克逊在Java端Json.Net在.NET结束),我猜大概可以做的,但只有在重映射的东西在每年年底大力度只要对象变得相当复杂。

I've looked a bit at JSON (Jackson on the Java end and Json.Net on the .Net end), and I'm guessing it can probably be done, but only with major efforts on remapping things at each end as soon as the objects become fairly complicated.

任何其他建议?基于JSON或以其他方式?

Any other suggestions? JSON-based or otherwise?

PS。我的问题是有点与此相关的一个<一个href="http://stackoverflow.com/questions/3905807/mapping-tool-for-converting-javas-json-to-from-c-sharp">Mapping工具将Java的JSON /从C#,但它从来没有得到一个合适的答案,也许是由于这个问题没有足够的信息。另外,我不在乎我是否最终会使用基于JSON的运输或XML或别的东西。

PS. My question is somewhat related to this one Mapping tool for converting Java's JSON to/from C#, but it never got a suitable answer, perhaps due to insufficient info in the question. Also, I don't care whether I end up using a JSON-based transport or XML or something else.

推荐答案

SO用户默认区域设置应该得到的荣誉,这一点,但他/她只能通过评论回答。所以,这只是为了很清楚我的选择是我来回答我的问题。

SO user "default locale" should get the honor for this, but he/she has only answered via a comment. So just to make it very clear what my choice was I'll answer my own question.

我已经决定去与谷歌协议缓冲器,这在我看来有移动物体来回Java和.NET之间的比JSON更好的支持。因为我有很多用C#的经验,很多现有的C#-defined类的,我选择了马克Gravell的protobuf网计划为.NET结束,谷歌自己的支持,为Android的结束(无 - 见编辑) 。这意味着,我定义在C#中的对象,而不是在.proto文件 - protobuf网生成.proto文件从我然后生成Java code

I've decided to go with Google Protocol Buffers, which in my opinion has much better support for moving objects back and forth between Java and .Net than JSON. Because I have a lot of experience with C#, and a lot of existing C#-defined classes, I've selected Marc Gravell's protobuf-net program for the .Net end, and Google's own support for the Android end (no - see edit). This implies that I'm defining the objects in C#, not in .proto files - protobuf-net generates the .proto files from which I then generate the Java code.

另外,作为传输机制,我使用了一个名为纳迦在Android端鲜为人知的计划。 HTTP://$c$c.google.com/p/naga/ 娜迦似乎做工精细,并详细记录,并有示例程序,在我看来应该更好地了解。

Incidentally, as the transport mechanism I'm using a little-known program called naga on the Android end. http://code.google.com/p/naga/ Naga seems to work fine, and is well-documented and has sample programs, and should be better known in my opinion.

编辑:

OK,我有现在的工作让我满意。下面是我使用的是什么:

OK, I've got it working now to my satisfaction. Here's what I'm using:

谷歌协议缓冲区作为交换格式: https://developers.google.com/protocol-buffers /

Google Protocol buffers as the interchange format: https://developers.google.com/protocol-buffers/

马克Gravell的protobuf网在C#结尾:的http:// code.google.com / P / protobuf网/

Marc Gravell's protobuf-net at the C# end: http://code.google.com/p/protobuf-net/

称为所谓protostuff的Java端程序:的http:// code .google.com / P / protostuff /

A program called called protostuff at the Java end: http://code.google.com/p/protostuff/

(我preFER protostuff到谷歌官方的Java实现,由于谷歌的执行协议缓冲区是基于Java对象是不可改变的。)

(I prefer protostuff to the official Google Java implementation of protocol buffers due to Google's implementation being based on the Java objects being immutable.)

其实,我没有使用纯粹的协议缓冲区作为交换格式 - 我preFIX的(最外层)类的名称中的数据传输。这使得数据自识别为反序列化在另一端

Actually, I'm not using pure protocol buffers as the interchange format - I prefix the data with the name of the (outermost) class being transmitted. This makes the data self-identifying for deserializing at the other end.

这篇关于爪哇 - .NET对象交换,而不是基于Web的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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