与非 .NET 应用程序交互时如何确保与 DataContractSerializer 的互操作性?
假设我有一个非 .NET 应用程序,需要写入要由 .NET 应用程序通过 DataContractSerializer 反序列化的数据。 描述所需的确切格式的规范在哪里?
这样的规范应该描述很多内容,包括:
- 同级元素的顺序重要吗?
- xml 命名空间 URI 是否应该始终以
http://schemas.datacontract.org/2004/07/
开头? - z:Id 和 z:Ref 值需要是连续的还是其他值? (假设
preserveObjectReferences==true
)(好吧,我猜MSDN 说这种情况甚至不能互操作) - 等
似乎是一个简单的问题,不是吗?但我没有在 MSDN 中看到直接解决这个问题。 (我发现的只是 论坛帖子说非 .NET 应用程序需要首先向 .NET 应用程序请求 WSDL 规范文件,但这似乎是错误的。)
(除了 DataContractSerializer 之外,我不使用 WCF 中的任何内容)
Say I have a non-.NET app which needs to write data to be deserialized by a .NET app via DataContractSerializer. Where's the specification describing the exact format necessary?
Such a spec should describe a lot of stuff, including:
- Does the order of sibling elements matter?
- Should the xml namespace URIs always begin with
http://schemas.datacontract.org/2004/07/
? - do z:Id and z:Ref values need to be sequental or anything? (assuming
preserveObjectReferences==true
) (ok, I guess MSDN says this case is not even interoperable) - etc
Seems like a simple question, doesn't it? Yet I don't see it addressed directly in MSDN. (all I found was forum-posts saying the non-.NET app needs to ask the .NET app for a WSDL spec file first. But that seems wrong.)
(I don't use anything from WCF other than the DataContractSerializer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们使用 WSDL 在 Java 和 .net 应用程序之间传达服务定义,它对我们来说工作得很好。
您需要注意的一件事是您使用哪些数据类型,请使用两个系统都能理解的数据类型,例如:
We use the WSDL to comunicate the service definition between Java and .net applications, it works fine for us.
One thing that you need to watch out for is which datatypes you use, use those that are understood by both systems, for example:
DataContractSerializer 不是 WCF 的一部分,它是 WCF 所依赖的运行时序列化的一部分。
我过去曾使用 DataContractSerializer 从通过 xml 转换生成的 XML 中反序列化对象。这可能符合您想做的事情。
为了弄清楚序列化器需要什么 XML,我发现编写一小段代码将我的对象序列化为字符串以查看它的结构以及 XML 命名空间是什么会更容易。
通过此信息,您可以了解如何构造 XML,还可以获取 xml 架构以进行额外验证。
The DataContractSerializer is not part of WCF, it is part of the runtime serialization which WCF is dependent on.
I have in the past used the DataContractSerializer to deserialize objects from XML I have generated out of an xml transform. This could be down the lines of what you want to do.
In order to work out what the XML required for the Serializer I found it easier to write a small piece of code that serialized my object out to a string to see how it should be structured and what the XML namespaces were.
With this information you can see how to structure the XML and you can also grab the xml schemas for extra validation.