title: Returning a inherited class as base class type with Web Services
body: <p>I suspect I am being very silly here but I have the following setup </p>
  
  <pre><code>Class MustInherit myBaseClass
  'some stuff
  
  End Class
  
  Class myInheritedClassA 
          inherits myBaseClass
  
  'some more stuff
  End Class
  
  
  Class myInheritedClassB 
          inherits myBaseClass
  
  'some more stuff
  End Class
  </code></pre>
  
  <p>I then have a web service that has a method </p>
  
  <pre><code>Function getSomeClass(id) as myBaseClass
  'a factory here dependent on the id will generate a myInherited Class
  return CType(aInstanceOfInheritedClass, mybaseClass)
  
  End function
  </code></pre>
  
  <p>Running this results in the following error</p>
  
  <pre><code>Unhandled Exception: System.InvalidOperationException: 
     There was an error generating the XML document. ---&gt; 
     System.InvalidOperationException: 
     The type &lt;type&gt; was not expected. 
     Use the XmlInclude or SoapInclude attribute to specify types 
     that are not known statically." 
  </code></pre>
  
  <p>So my question is, is there any way of 'Widening' the inherited class to the base class so this would work? </p>
  
  <p>EDIT: RE: the suggestion regarding XmlInclude(typeof inheritedClass), currently this method could potentially return a number of types of inherited class (i.e myInheritedClassA and myInheritedClassB) is it case of simply having to add each of the inheritedTypes in this tag? </p>
  
  <p>I have amended the example to hopefully make things clearer</p>