Every example out there – you declare any ‘model types’ as though they belong to the web service- and this is fine for the trivial example, BUT in an application where you are using shared libraries – you WANT the behaviour I am describing. References to assemblies – use your classes – send them to the web service and they stars align.
The answer is dumb. Make your ‘model types’ in your library assembly XML serializable. You can add some simple attributes like:
[System.Xml.Serialization.XmlTypeAttribute(Namespace=http://tempuri.org/FooConcreteA.xsd)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/FooConcreteA.xsd", IsNullable=false)]
public class FooConcreteA : AbstractFooBase
You can also get deeper (you will want to) and assign more granular XML serialization attributes. You can add references to this library assembly to your client project as well as to your web service project. This is the dumb part. Now – make a method that returns a model type and build. Now add a web reference to your client project and build. You get – under the ‘web service’ reference node in your project a ‘Reference.map’ – under that is a ‘Reference.cs’ file. See how your web service proxy is created and a new serializable class with the same name as your original class is created (somewhere near the bottom)? – Comment out that class and add a using your library statement on the top of this class. Now – you are apples to apples – you are referencing the SAME class that is from your library – not this new ghost class that was created for you. So – you can simply use your locally referenced class and hand it to the web service
Problem 2 – Now we have our nice – rich domain mode. We have objects that contain other objects etc. The issue now is…Objects vs data elements. We have some interfaces and/ or abstract classes. When you make a local reference to a class – you ‘have’ all of it’s methods/ properties – you just need to cast to get pointers to the interface/ class members. When you serialize an abstract class – you get the serialized base information only. For example:
WindowsApplication1.WebService1.Service1 svs = new WindowsApplication1.WebService1.Service1();
//HelloWorld() returns AbstractFooBase – like a factory
AbstractTest.FooConcreteA fooConcreteA = (FooConcreteA)svs.HelloWorld();
This type of thing just does not work. You cannot use any object inheritence (as I can see it) via web service. So – when you have a class that contains a collection of abstract types – you need to manage them EACH BY THEIR INDIVIDUAL CONCRETE TYPE – thereby killing the usefullness of objects.
Still workin’ on our incarnation of an answer ….
