简体   繁体   English

WCF REST Xml响应键入

[英]WCF REST Xml Response Typing

I have a WCF REST service that exposes a couple dozen objects and based on the url format routes calls though 3 different method. 我有一个WCF REST服务,该服务公开了几十个对象,并且基于url格式通过3种不同的方法路由调用。 For example: 例如:

Protected Function [get](ByVal objType As String, ByVal id As String, ByVal propertyList As String, ByVal token As String) As Object

Each one of these methods returns an Object or BaseObj (from which all our returned types inherit). 这些方法中的每一个都返回一个Object或BaseObj(我们所有返回的类型都将从其继承)。 The ultimate problem, though, is that when I view the XML, I get a wrapper like: 但是,最终的问题是,当我查看XML时,得到了一个包装器,例如:

<ArrayOfBaseObj xmlns="http://objects/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <BaseObj i:type="Event">
        <!-- Event object details -->
    </BaseObj>
</ArrayOfBaseObj>

instead of elements typed the same as the actual object that's returned like: 而不是键入与返回的实际对象相同的元素,例如:

<ArrayOfEvent xmlns="http://objects/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Event>
        <!-- Event object details -->
    </Event>
</ArrayOfEvent>

Is there anyway to make the XML serializer use the type name for the wrapping elements rather than the base type? 无论如何,要使XML序列化程序使用包装元素的类型名称而不是基类型? JSON appears to return the type correctly, it's just the xml serialization that I'm not completely stoked about. JSON似乎正确返回了类型,这只是我不完全了解的xml序列化。

You need to add the attribute [CollectionDataContract]. 您需要添加属性[CollectionDataContract]。 Check the article http://msdn.microsoft.com/en-us/library/dd203052.aspx for more info. 查看文章http://msdn.microsoft.com/en-us/library/dd203052.aspx,以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM