1

我正在用 C# 中的 WCF 构建一个 SOAP 服务器。我有一个来自客户的请求,看起来像这样:

<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"          
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<sendLocalListRequest xmlns="urn://Ocpp/Cp/2012/06/">
  <updateType>Full</updateType>
  <listVersion>5678</listVersion>
  <localAuthorisationList>
    <idTag>1111111</idTag>
    <idTagInfo>
      <status>Accepted</status>
      <expiryDate>2015-10-27T00:00:00</expiryDate>
      <parentIdTag>555</parentIdTag>
    </idTagInfo>
  </localAuthorisationList>
  <localAuthorisationList>
    <idTag>2112432</idTag>
    <idTagInfo>
      <status>Accepted</status>
      <expiryDate>2015-10-29T00:00:00</expiryDate>
      <parentIdTag>555</parentIdTag>
    </idTagInfo>
  </localAuthorisationList>
  <localAuthorisationList>
    <idTag>44444444</idTag>
    <idTagInfo>
      <status>Accepted</status>
      <expiryDate>2015-10-29T00:00:00</expiryDate>
      <parentIdTag>2222</parentIdTag>
    </idTagInfo>
  </localAuthorisationList>
  <hash>bhghs77767676777</hash>
</sendLocalListRequest>

我必须获取此请求并将 Elements localAuthorisationList之间的数据存储在硬盘上的文件中。我做了一个 [MessageContract] 看起来:

[MessageContract(IsWrapped = true, WrapperName = "sendLocalListRequest", 
WrapperNamespace = "urn://Ocpp/Cp/2012/06/")]    
public class sendLocalListRequest
{      
 [MessageBodyMember(Order=1)]
 public UpdateType updateType;

 [MessageBodyMember(Order=2)]
 public int listVersion;

 [MessageBodyMember(Order=3)]
 public localAuthorisation[] localAuthorisationList;

 [MessageBodyMember(Order=4)]
 public string hash;
}



[DataContract(Namespace = "urn://Ocpp/Cp/2012/06/")]

public class localAuthorisation 
{
 [DataMember(IsRequired=true, Name = "idTag", Order = 1)]
 public string idTag;

 [DataMember(Name="idTagInfo", Order=2)]
 public Data idTagInfo;
}


 [DataContract(Namespace = "urn://Ocpp/Cp/2012/06/")]
 public class Data 
{
 [DataMember(Name = "status", Order=1)]
 public string Status;

 [DataMember(Name = "expiryDate", Order=2)]
 public DateTime ExDate;

 [DataMember(Name = "parentIdTag", Order = 3)]
 public string parentTag;
}

但是使用 WCFTestClient 我得到以下请求:

<s:Body>
<sendLocalListRequest xmlns="urn://Ocpp/Cp/2012/06/">
  <updateType>Differential</updateType>
  <listVersion>0</listVersion>
  <localAuthorisationList xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <localAuthorisation>
      <idTag>sfdsdgfg</idTag>
      <idTagInfo>
        <ExDate>2015-11-02T16:37:00</ExDate>
      </idTagInfo>
    </localAuthorisation>
    <localAuthorisation />
    </localAuthorisationList>
   <hash i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" />
  </sendLocalListRequest>
</s:Body>

我的问题是,我的元素太多(localAuthorisationList 或 localAuthorisation)。我可以消除一个元素吗?如何?

谢谢您的帮助

汤姆

4

0 回答 0