Web Service and inheritance problem
We have a set of classes that look like this -
If we create a schema for ContainerClass using XSD.exe it looks like this -
All good so far, and indeed serialization and deserialization between the two work just fine.
We’ve then created a web method that returns ContainerClass, as such -
public ContainerClass ReturnContainer()
ContainerClass cc = new ContainerClass();
cc.Items = new System.Collections.Generic.List
Looking at the rendering of the WSDL in IE it looks promising -
You can notice the WSDL tells us we will get a ContainerClass with an Items element, and in that we would get Item, Sub Item and/or AnotherSubItem as expected.
What happens if we call the web methods then? (remember that the web methods adds one of each type to the list) -
We've created a windows app, added a web reference and called the web method - here's what we've received back -
You will immediately notice that the first member added to the Items list in the web method - Item - does not appear to reach the client.
Using HTTP analyser we've sniffed for the stream coming back from the web service, and it did contain all three members, the "Item" one was removed in the serialisation from the stream to the class.
As we've tested the serialisation before, we knew it should work, so we had to look at the proxy generated - and this is when the problem became apparent - here's the relevant extract from the generated proxy -
WSDL exe - when generating the proxy - has "kindly" decided to remove the XmlArrayItem option we've explicitly added for "Item" and only included "SubItem" and "AnotherSubItem".
This meant that the client did not know how to deserialise the Item member of the list and it got emmitted from the deserialised class.
By adding the missing XmlArrayItemAttribute following line to the proxy we've managed to get all 3 items without touching the web service.
As this is not something we would like to do in production code we've opened a call with Microsfot to try and see what we can do, but we're obviously open to suggestions, anyone?