views:

28

answers:

1

I have an xml schema with a type defined like this:

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

where the ArrayOfstring type is defined as

  <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" />

How can I deserialize the InteractiveWorkflowAddress type using the DataContract attribute? I tried the following

[DataContract(Namespace = Constants.Namespace)]
public class InteractiveWorkflowAddress {
    [DataMember()]
    public string[] EndpointAddresses;
    [DataMember()]
    public string InstanceId;
}

But while the InstanceId member is deserialized correctly, EndpointAddresses is always null.

A: 

The best way to figure out how something can be deserialized, is to first serialize. Serialize that InteractiveWorkflowAddress data structure and see the XML is creates. You might be able to List instead of string[] - and also you can control serialization with [XmlArray(...)] and [XmlArrayItem(...)] - which may help too.

The easist way is likely going to be doing some quick trial-and-error, by: making a change, serializing the class, seeing the output - then repeat. Hope that helps!

Robert Seder
The serialization idea is good indeed; but are the XmlArray and XmlArrayItem supposed to make any difference when deserializing with DataContractSerializer? Shouldn't I rather use the DataContractCollection attribute?
Paolo Tedesco