从WCF(或Web API)对.Net客户端中的对象进行反序列化的最佳方法,而无需使用内置的反序列化器 [英] Best way to deserialize object in .Net client from WCF (or Web API) without using built-in deserializers

查看:88
本文介绍了从WCF(或Web API)对.Net客户端中的对象进行反序列化的最佳方法,而无需使用内置的反序列化器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Unity3D客户端/服务器项目.客户端将在Unity3D中完成.我已经有一个基于.Net的服务器,该客户端将使用该服务器.该服务器可以调整为使用WCF甚至ASP.Net Web API.但是Unity3D网络播放器的基本类 库与System.ServiceModel不兼容,因此我无法反序列化来自WCF服务的消息.同样,Web API客户端也退出了,因为Unity3D仅与.Net 3.5及更早版本兼容.

I'm working on a Unity3D client / server project. The client will be done in Unity3D. I already have a server built on .Net that this client will use. The server could be adapted to use WCF or even ASP.Net Web API. However the Unity3D web player base class libraries are incompatible with System.ServiceModel so I can't deserialize messages coming from a WCF service. Similarly the Web API client is out because Unity3D is only compatible with .Net 3.5 and earlier.

这意味着我没有真正简单的方法来使用WCF或ASP.Net Web API服务.如果我使用Unity的WWW类对这两个API之一进行调用,则会在我的Unity代码中得到一个大而丑陋的序列化.NET对象来处理 不幸:(.

This means that I have no really easy way to consume either a WCF or a ASP.Net Web API service. If I use Unity's WWW class to make calls to one of these two APIs I would be given a big and ugly serialized .NET object to deal with in my Unity code which would be unfortunate :(.

有人知道有什么好方法可以在客户端上反序列化这些.NET对象,而无需手动完成所有操作吗?

Does anyone know of any good methods for deserialzing these .NET objects on the client side without doing it all manually?

也许有一种无需使用System.ServiceModel即可挂接到WCF客户端反序列化器的方法吗?从本质上来说,这给了我一种从WCF服务获取原始XML,然后将其馈送到某些.NET类以将其转换为对象的方法吗?

Maybe there's a way to hook into the WCF client deserializers without using System.ServiceModel? Essentially giving me a way to get the raw XML from the WCF service and then feed that to some .NET classes to turn them into objects?

也许某个地方有一个Codeplex项目或其他一些代码可以复制不依赖于System.ServiceModel的这些.NET客户端库中的功能?

Maybe there's a codeplex project or some other code somewhere that duplicates the functionality in these .NET client libraries that's not dependent on System.ServiceModel?

我知道我可以手动序列化对byte []或xml的每个调用的输出,并手动反序列化客户端上的所有内容,但是出于某些原因,我想避免这种情况.

I know I could manually serialize the output of each call to byte[] or xml and manually deserialize everything on the client but I would like to avoid that for a few reasons.

  1. KnownTypeAttribute很难使用.
  1. You can't tell what the service is returning by looking at the contract.
  2. The KnownTypeAttribute is a pain in the butt to work with.

Any help much appreciated!

推荐答案

我正在研究一个几年前编写的项目,它使用WCF,XML和Oracle以及DAL技术在WCF Web服务后面. XML在WCF客户端和服务之间作为字符串数据发送,并将字符串数据加载到XML Document对象中 供双方使用.客户端和服务之间没有发送可序列化的DTO或自定义对象时间段.
I am working on a project that was written a few years ago, it uses WCF, XML and Oracle with DAL sitting behind the WCF Web service. The XML is sent between the WCF client and service as string data, and the string data is loaded into a XML Document object to be used by both sides. There are no serializable DTO(s) or custom objects period being sent between the client and the service. 


这篇关于从WCF(或Web API)对.Net客户端中的对象进行反序列化的最佳方法,而无需使用内置的反序列化器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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