I've got some somewhat old school web services that I need to talk to. They are somewhat REST-like, in that they are called with regular GET and POST HTTP requests, and return WDDX-formatted data in the response body.
The consumer code in this instance is .NET. Ideally, I'd like to use WCF to take advantage of all of its magic. The sticking point is that WDDX doesn't really seem to fit into its model very well. On the one hand, it doesn't map straight to the types and properties of the objects in the API in the way that the XML serialization expects. WDDX is actually very similar to JSON, but XML. On the other hand, I want deserialization to my types, rather than generic arrays and dictionaries.
I can certainly plug in an IClientMessageInspector
to transform the WDDX, but I'm not sure of the best approach. Does anyone know whether the Infoset-based format that WCF seems to use internally for JSON works with the regular DataContractSerializer
?
Should I be writing my own IClientMessageFormatter
to handle the WDDX? (Seems like there'd be a lot of reflection code needed to map that back to my types that I'd rather not write.)
Something I'm missing?
EDIT: In the hope that some examples might elucidate things:
Here's an example of the sort of simple types in the API, in the form that I'd like to have them in the consumer code:
public class Foo {
public string First { get; set; }
public string Second { get; set; }
public int Third { get; set; }
}
public class FooList : List<Foo> {
}
public class Bar {
public string Eins { get; set; }
public Foo Zwei { get; set; }
}
Conventional XML serialization would tend to render documents like these:
<FooList>
<Foo>
<First />
<Second />
<Third />
</Foo>
<Foo>
<First />
<Second />
<Third />
</Foo>
</FooList>
<Bar>
<Eins>
<Zwei>
<First />
<Second />
<Third />
</Zwei>
</Bar>
While in WDDX format, those would look like this (again, note the similarity to JSON):
<array>
<struct>
<var name="First"><string></string></var>
<var name="Second"><string></string></var>
<var name="Third"><number></number></var>
</struct>
<struct>
<var name="First"><string></string></var>
<var name="Second"><string></string></var>
<var name="Third"><number></number></var>
</struct>
</array>
<struct>
<var name="Eins"><string></string></var>
<var name="Zwei">
<struct>
<var name="First"><string></string></var>
<var name="Second"><string></string></var>
<var name="Third"><number></number></var>
</struct>
</var>
</struct>