scratching my head on WCF … I’ve got XML messages where the children of <DataFields> could be anything, e.g. …
<Test1Root>
<CaseNo></CaseNo>
<Activity></Activity>
<DataFields>
<AccountRef></AccountRef>
<PropRef></PropRef>
<User></User>
</DataFields>
</Test1Root>
I’ve handled this in BizTalk using the <xs:any> for the <DataFields> …
<xs:element name="DataFields">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip" />
</xs:sequence>
</xs:complexType>
</xs:element>
But I’m struggling to see how to handle this in a WCF [DataContract] …
I tried using both svcutil.exe and xsd.exe to create the classes, and they both give the main elements (CaseNo, Activity, etc.) but neither seems to handle the xs:any of DataFields …
- svcutil has DataFields as an XmlElement
- xsd has it as a class, but with an Any property of type XmlElement []
Is it possible to get a better handling of the child elements ?
Well,
xs:anycan be anything, so the best the .NET tools could do is give you an array of objects….Since it can be anything, there’s really not much you can do about it, right? It could be anything… so you need to use a type that could be anything.
If you really need that
xs:anyin your XML schema, and can’t replace by e.g. a set of more specificxs:element(possibly inheriting from one another), I don’t see how you could get better support…