views:

38

answers:

2

Hello,

I have a test web service with following methods & classes,

Method

public String addPerson(Person p) {
if(p instanceof Employee) {
return "Employee"; 
}
return "Person";
}

Note: Method is annotated with @WebMethod, @WebParam annotations, so is web service with @WebService.

Classes

Class Person {
public String name;
}

Class Employee extends Person{
public int employeeNo;
}

Observations

  1. In spite of client sending the serialized Employee object the web service is always taking it as a Person object. I have checked the soap packet on client with firebug tool, employee number is present in the payload. I also check soap MESSAGE on server & their I dont see employee number attribute.

Question

  1. Is this an expected behavior? I hope it is not.
  2. Is there any way I can make this work without having write custom SOAP decoders?
A: 

I think this is how it should be. Because when the data is sent the inheritance information is lost and it will only decode the data back to the type declared in the webservice method in your case to the Person object.

Faisal Feroz
Thanks Faisal. If thats true then how do you get type inheritance to work with web services?
Chetan
I have checked wsdl of another system (unfortunately not open source). It does what we are looking to achieve.
Chetan
A: 

After digging deep, we found out that the issue was with the client side which generated SOAP packet which doesn't work in such scenario. Client is expected to put name(s) of type of derived object(s) (Employee) in the element corresponding to the operation but the client we are using is not doing so because of which "javax.xml.bind.UnmarshalException: Unable to create an instance of ..." is reported.

Chetan