开发者

WCF REST Xml Response Typing

开发者 https://www.devze.com 2023-01-28 22:02 出处:网络
I have a WCF REST service that exposes a couple dozen objects and based on the url format routes calls though 3 different method.For example:

I have a WCF REST service that exposes a couple dozen objects and based on the url format routes calls though 3 different method. 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 o开发者_如何学Pythonf these methods returns an Object or BaseObj (from which all our returned types inherit). The ultimate problem, though, is that when I view the XML, I get a wrapper like:

<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? JSON appears to return the type correctly, it's just the xml serialization that I'm not completely stoked about.


You need to add the attribute [CollectionDataContract]. Check the article http://msdn.microsoft.com/en-us/library/dd203052.aspx for more info.

0

精彩评论

暂无评论...
验证码 换一张
取 消