views:

144

answers:

1

Hi *

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 ;)

A: 

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.

Christian Hayter
I haven't any DLL, my service is in java and client is a SilverLight application.
Amir Borzoei
OK, let me clarify: If your web service classes were written in .NET, Java, or anything else that uses class-based object orientation, you would still have the same problem, and the same solution. Just cast the returned object to `ChildClass` and have done with it. You're making this more complex than it needs to be.
Christian Hayter
Oh, my friend when I generate proxy in client side, Visual Studio don't generate any proxy for child class. VS just generate proxy for parent class. So I haven't ChildClass to downcast. ok?
Amir Borzoei
When creating JAX-WS webservice (with automatic WSDL generation), if a class is not included in any input / output parameters of any service, even though there is a parent / child relation, the proxy code will NOT get generated for that class.
Hadi Eskandari
Ok, tanx for your attention :)
Amir Borzoei