C# 使用DataContract反序列化字符串数组

C# 使用DataContract反序列化字符串数组,c#,arrays,datacontract,C#,Arrays,Datacontract,我有一个xml模式,其类型定义如下: <xs:complexType name="InteractiveWorkflowAddress"> <xs:sequence> <xs:element name="endpointAddresses" nillable="true" type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/A

我有一个xml模式,其类型定义如下:

  <xs:complexType name="InteractiveWorkflowAddress">
    <xs:sequence>
      <xs:element name="endpointAddresses" nillable="true" type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
      <xs:element name="instanceId" type="ser:guid" />
    </xs:sequence>
  </xs:complexType>

但是,尽管InstanceId成员已正确反序列化,EndpointAddresses始终为空。

了解如何反序列化内容的最佳方法是首先序列化。序列化InteractiveWorkflowAddress数据结构并查看创建的XML。您可以使用列表代替字符串[],还可以使用[XmlArray…]和[XmlArrayItem…]控制序列化,这可能也会有所帮助


easist的方法可能是做一些快速的尝试和错误,方法是:进行更改,序列化类,查看输出,然后重复。希望有帮助

序列化的想法确实不错;但是,当使用DataContractSerializer进行反序列化时,XmlArray和XmlArrayItem应该有什么区别吗?我不应该使用DataContractCollection属性吗?
  <xs:complexType name="ArrayOfstring">
    <xs:sequence>
      <xs:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
  <xs:element name="ArrayOfstring" nillable="true" type="tns:ArrayOfstring" />
[DataContract(Namespace = Constants.Namespace)]
public class InteractiveWorkflowAddress {
    [DataMember()]
    public string[] EndpointAddresses;
    [DataMember()]
    public string InstanceId;
}