我将从Android应用程序(java)发送xml数据的个别帖子到.net 4 WCF Web服务。 xml创建如下
xmlBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xmlBuilder.append("<LogDeviceCommunication
xmlns=\"http://schemas.datacontract.org/2004/07/conxEntities\">");
xmlBuilder.append("<DeviceID>").append(DeviceID).append("</DeviceID>");
xmlBuilder.append("<ID>").append(ID).append("</ID>");
xmlBuilder.append("<Info>").append(Info).append("</Info>");
xmlBuilder.append("<Line>").append(Line).append("</Line>");
xmlBuilder.append("<Tab>").append(Tab).append("</Tab>");
xmlBuilder.append("<Time>").append(new DateTime(Time).toDateTimeISO()).append
("</Time>");
xmlBuilder.append("</LogDeviceCommunication>");
WCF方法如下
[OperationContract]
[WebInvoke(UriTemplate = "AddDeviceCommunicationLog", RequestFormat =
WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, Method = "POST")]
string AddDeviceCommunicationLog(LogDeviceCommunication deviceCommunicationEntry);
我想更改为发送LogDeviceCommunication列表以加快速度但不确定要用作父元素的内容,即
<parent element>
<logdevicecommunication>...</logdevicecommunication>
<logdevicecommunication>...</logdevicecommunication>
<logdevicecommunication>...</logdevicecommunication>
</parent element>
调用WCF通常会将List作为ArrayOf返回....但发布时自然不存在此类型。 我是否需要创建一个messagecontract或类似的东西?
谢谢
答案 0 :(得分:1)
您只需要一个集合数据合同类型,例如:
[CollectionDataContract(Name="WhateverYouWantToCallTheRootElement")]
public class LogDeviceCommunications: Collection<LogDeviceCommunication> {}
然后更改你的operaton方法以获取这个新类型的参数。