在WCF服务中重命名__type-field [英] Rename __type-field in WCF services

查看:190
本文介绍了在WCF服务中重命名__type-field的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以GeoJSON映射到DataContracts在工作中的一些WCF服务的使用。
以GeoJSON有一个称为类型字段和DataContracts序列化取决于场的 _ 的_type支持德/序列化到正确的亚型。以GeoJSON规范后,我DataContracts都命名,我设置了DataContracts的命名空间为,所以基本上我已成功地实现以GeoJSON< ==> DataContracts如果我能告诉(反)序列化使用田字型,而不是场__type。

I'm trying to map GeoJSON to DataContracts for use in some WCF-services at work. GeoJSON has a field called "type" and the DataContracts-serialization depends on the field "__type" to support de/serializing to the correct subtypes. My DataContracts are all named after the GeoJSON spec and I've set the Namespace of the DataContracts to "", so basically I have managed to implement GeoJSON <==> DataContracts if only i could tell the (de)serializer to use the field "type" instead of the field "__type".

时它在所有可能告诉WCF或DataContract序列化来看待的类型信息领域是什么?如何将一个去支持JSON-标准的实际的使用__type场?

Is it at all possible to tell WCF or the DataContract serializers what field to look at for type information? How would one go about to support a JSON-standard that actually uses the __type-field?

推荐答案

你不能。 __type是在DataContractJsonSerializer最基本的层面硬编码

You can't. __type is hardcoded in at the most basic level in DataContractJsonSerializer.

您可能有一个选项是包装这个围绕另一个串行器,数据合同解析器,数据契约替代,绘制无论是在__type输入(在序列化),转让无论是在类型__type(上反序列化)。这是额外的手动工作那是相当头痛。

One option you potentially have is to wrap this around ANOTHER serializer, a data contract resolver, or a data contract surrogate, to map whatever is in __type to type (on serialization) and to transfer whatever is in type to __type (on deserialization). This is extra manual work that is quite the headache.

你有另一种选择是写自己的序列化。这是不是很难做,因为你可能会认为,如果你只需要通过反射来看看如何DataContractJsonSerializer,并与您的作者和读者模仿它,并且还分析在DataContractJsonSerializer使用或实例。

Another option you have is to write your own serializer. This is not as hard to do as you might think, if you just take a look at how DataContractJsonSerializer via Reflector, and mimic it with your writer and reader, and also analyze where DataContractJsonSerializer is used or instantiated.

你有第三种选择是只可能是另一个完全序列化器一样,JSON .NET

A third option you have is to to just perhaps another serializer altogether, like JSON .NET

第四个选项是使用MicrosoftAjax.js ,这确实明白__type,然后以某种方式与以GeoJSON配合使用,(我不知道如果这甚至有可能,但只是把它扔在那里作为一个潜在的想法)

A fourth option is to use MicrosoftAjax.js, which does understand __type, and then somehow use it in conjunction with GeoJSON (I don't know if that's even possible, but just throwing it out there as a potential idea)

这篇关于在WCF服务中重命名__type-field的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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