【发布时间】:2023-03-10 05:48:01
【问题描述】:
我有一个 WCF REST 服务,它公开了几十个对象,并基于 url 格式通过 3 种不同的方法路由调用。例如:
Protected Function [get](ByVal objType As String, ByVal id As String, ByVal propertyList As String, ByVal token As String) As Object
这些方法中的每一个都返回一个 Object 或 BaseObj(我们所有返回的类型都从它们继承)。然而,最终的问题是,当我查看 XML 时,我得到了一个如下的包装器:
<ArrayOfBaseObj xmlns="http://objects/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<BaseObj i:type="Event">
<!-- Event object details -->
</BaseObj>
</ArrayOfBaseObj>
而不是输入与返回的实际对象相同的元素,例如:
<ArrayOfEvent xmlns="http://objects/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Event>
<!-- Event object details -->
</Event>
</ArrayOfEvent>
有没有办法让 XML 序列化程序使用包装元素的类型名称而不是基本类型? JSON 似乎正确地返回了类型,这只是我不完全兴奋的 xml 序列化。
【问题讨论】:
标签: xml wcf rest xml-serialization