views:

237

answers:

1

I have a WebService that returns complex objects.

public class Resource;    
public class Asset extends Resource;
public class Collection extends Resource;

The methods that return the subclasses work fine:

Asset[] getAssets();
Collection[] getCollections();

However the methods that return the base class are generating an exception:

Resource[] getResources();

The WebService itself is written in java using CXF but I dont think that matters. I am able to use even the base class methods with a sample client created with java.

Here is the exception using .Net Client:

`Unhandled Exception: System.InvalidOperationException: There is an error in XML document (1, 173). ---> System.InvalidOperationException: The specified type was not recognized: name='asset', namespace='http://www.turimsaint.com/', at <return xmlns=''>`.

Here is the client Code Generated by wsdl.exe

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("", RequestNamespace = "http://www.turimsaint.com/", ResponseNamespace = "http://www.turimsaint.com/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("return", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public Resource[] getCollectionContents([System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] Collection p_collection)
{
    object[] results = this.Invoke("getCollectionContents", new object[] {
            p_collection});
    return ((Resource[])(results[0]));
}

And lastly this is the wsdl for the related elements:

- <xs:complexType name="collection">
- <xs:complexContent>
- <xs:extension base="tns:resource">
- <xs:sequence>
  <xs:element name="_instructor" type="xs:string" /> 
  </xs:sequence>
  </xs:extension>
  </xs:complexContent>
  </xs:complexType>
- <xs:complexType abstract="true" name="resource">
- <xs:sequence>
  <xs:element name="_title" type="xs:string" /> 
  <xs:element name="_deepLink" type="xs:string" /> 
  <xs:element name="_id" type="xs:string" /> 
  <xs:element name="_description" type="xs:string" /> 
  <xs:element name="_type" type="xs:string" /> 
  <xs:element maxOccurs="unbounded" name="_metadata" type="tns:resourceMetadata" /> 
  </xs:sequence>
  </xs:complexType>

....

- <xs:complexType name="getResourceByIDResponse">
- <xs:sequence>
  <xs:element minOccurs="0" name="return" type="tns:resource" /> 
  </xs:sequence>
  </xs:complexType>

Any help appreciated. Thanks.

A: 

This is digging a little, its been a while since playing with .Net 2.0 style web service clients.

If i remember correctly, you´ll have to do some attribute work. You´ll have to inform the base class ´resource´ about the possibly derived classes ´Asset´-´Collection´ or methods returning one of the derived classes by placing attributes on top.

Have a look at

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlincludeattribute.aspx

Hope this helps,

Marvin Smit