2012-09-24 1 views
0

안드로이드 앱 (java)의 XML 데이터 게시물을 .net 4 WCF 웹 서비스로 보내고 있습니다.WCF에 필요한 XML 목록 유형

[OperationContract] 
    [WebInvoke(UriTemplate = "AddDeviceCommunicationLog", RequestFormat = 
    WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare, Method = "POST")] 
    string AddDeviceCommunicationLog(LogDeviceCommunication deviceCommunicationEntry); 

을 다음과 같이

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 방법은 내가 일을 속도를하지만 확실하지 않은 즉, 부모 요소로 무엇을 사용하는 LogDeviceCommunication의 목록을 보내기로 변경할 것입니다 다음과 같이 XML을 생성 WCF에

<parent element> 
    <logdevicecommunication>...</logdevicecommunication> 
    <logdevicecommunication>...</logdevicecommunication> 
    <logdevicecommunication>...</logdevicecommunication> 
</parent element> 

통화는 일반적으로 ArrayOf으로 목록을 반환 ....하지만 게시 할 때 자연적으로이 유형은 존재하지 않습니다. messagecontract 또는 유사하게 만들어야합니까?

감사

답변

1

당신은

[CollectionDataContract(Name="WhateverYouWantToCallTheRootElement")] 
public class LogDeviceCommunications: Collection<LogDeviceCommunication> {} 

그런 다음이 새로운 유형의 인수를 당신의 operaton 방법을 변경, 예컨대 : 컬렉션 데이터 계약 형식이 필요합니다.