How to generate proxy for a child class when my web service return a parent class?

I have a JAX-WS WebService like this:

public class ParentClass{
    public String str1;
}
public class ChildClass : ParentClass{
    public String str2;
}

public class WebService{
    public ParentClass WebMethod(){
        return GetFirstChildClass();    //Return a child class
    }
}

When I generate proxy for this web service by Visual Studio, VS just generate proxy for ParentClass but I need ChildClass too. For workaround I add a dummy method to WebService that return ChildClass to generate proxy for ChildClass in client.

public class WebService{
    ...
    //This is a dummy method to generate proxy for ChildClass in client.
    public ChildClass DummyWebMethod(){
        return null;
    }
}

In addition I write web service in java (JAX-WS) and my client is a SilverLight Application. Is there a better solution for this problem?

tanx for your help ;)

Answers


After a deep search in web found @XmlSeeAlso annotation to resolve this problems. We should add this annotation above our services to generate needed references, like: http://download.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/XmlSeeAlso.html

@XmlSeeAlso({ParentClass.class})
public class WebService{
...

If you called WebService.WebMethod directly as an in-process DLL, it would return a value of type ParentClass, which you would have to manually downcast to ChildClass. That is how inheritance and polymorphism are supposed to work. Why should a web service proxy class behave any differently?

EDIT: based on comments...

In a .NET WCF service, you would solve the problem by telling the serializer about the child class, e.g.

[DataContract]
[KnownType(typeof(ChildClass))]
public class ParentClass {
    public String str1;
}

[DataContract]
public class ChildClass : ParentClass {
    public String str2;
}

The child class is then included in the generated client proxy classes, and you can cast to it. I would imagine a similar mechanism exists in JAX-WS.


Need Your Help

Titanium - uisegmentedcontrol

javascript ios titanium uisegmentedcontrol

I'm trying to do something in titanium that is similar to the iphone uisegmentedcontrol

Python crashes when plotting with matplotlib in module importing swig generated wrapper

python crash matplotlib swig show

I have a python module that imports a module generated with swig. When I try to call the show() function of matplotlib later in that module, python crashes without any hint, what went wrong. When I