WCF 服务与 Datacontract 的 List 集合的 XML 输出问题
我是 WCF 新手,尝试以特定格式输出一些 XML。
目前,我的 ServiceEvents 对象包含 ServiceEvent 对象的集合(请参阅下面的类和 DataContracts)。当我通过 WCF 获取这些对象时,集合的 XML 输出将 Array0 附加到 Event 元素。对于使用 xml 的系统来说,这并不理想(请参阅下面的 xml)。
理想情况下,我也想从事件元素中删除属性 attr0="EventArray",但它的优先级较低。
如果有人能指出我正确的方向,我将不胜感激。
[ServiceContract]
public interface IEventAppService
{
[OperationContract]
ServiceEvents GetEvents();
}
[CollectionDataContract(Name = "Events")]
public class ServiceEvents : List<ServiceEvent>
{
public ServiceEvents(){}
public ServiceEvents(List<ServiceEvent> serviceevent)
{
base.AddRange(serviceevent);
}
}
[DataContract(Name = "Event")]
public class ServiceEvent
{
[DataMember]
public long ID
{
get;
set;
}
[DataMember]
public string Name
{
get;
set;
}
[DataMember]
public System.DateTime DateStart
{
get;
set;
}
[DataMember]
public System.DateTime DateEnd
{
get;
set;
}
}
<GetEvents>
<MethodParameters>
<Events attr0="EventArray"isNull="false">
<EventArray0>
<DateEnd>20/11/2011 12:00:00 AM</DateEnd>
<DateStart>10/11/2011 12:00:00 AM</DateStart>
<ID>2</ID>
<Name>Event1</Name>
</EventArray0>
</Events>
</MethodParameters>
</GetEvents>
I am new to WCF and trying to output some XML in a specific format.
Presently my ServiceEvents object holds a collection of ServiceEvent objects (See classes and DataContracts below). When I fetch these objects via WCF the XML output for the collection appends Array0 to the Event element. For the system consuming the xml this is not ideal (see xml below).
Ideally I would like to remove the attribute attr0="EventArray" from the Events element also but it is a low priority.
If somebody could point me in the right direction it would be much appreciated.
[ServiceContract]
public interface IEventAppService
{
[OperationContract]
ServiceEvents GetEvents();
}
[CollectionDataContract(Name = "Events")]
public class ServiceEvents : List<ServiceEvent>
{
public ServiceEvents(){}
public ServiceEvents(List<ServiceEvent> serviceevent)
{
base.AddRange(serviceevent);
}
}
[DataContract(Name = "Event")]
public class ServiceEvent
{
[DataMember]
public long ID
{
get;
set;
}
[DataMember]
public string Name
{
get;
set;
}
[DataMember]
public System.DateTime DateStart
{
get;
set;
}
[DataMember]
public System.DateTime DateEnd
{
get;
set;
}
}
<GetEvents>
<MethodParameters>
<Events attr0="EventArray"isNull="false">
<EventArray0>
<DateEnd>20/11/2011 12:00:00 AM</DateEnd>
<DateStart>10/11/2011 12:00:00 AM</DateStart>
<ID>2</ID>
<Name>Event1</Name>
</EventArray0>
</Events>
</MethodParameters>
</GetEvents>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论