WCF,肥皂 - >如何消除[MessageBodyMember]中的元素名称

时间:2015-11-02 16:06:50

标签: wcf soap request server messagecontract

我在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>

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

[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)。我可以消除一个元素吗?怎么样?

感谢您的帮助

汤姆

0 个答案:

没有答案