Rafael Ribeiro wrote:
Hi all,

 I have an webmethod that returns an arbitrary class. The problem is, on
some of its executions it might return some subclass of the class that is
expressed on the method signature. Instead of getting the actual class that
was serialized from the webservice the client is getting the class that is
expressed on the method. Do I have to specify anything on the classes that I
need to serialize or on the method in order for it to correct serialize the
expected class?

To get this working with JAX-WS you need to make sure that the JAXB context knows about all the possible concrete classes you could be returning. With a CXF 2.1 snapshot you might be able to do this with an @XmlSeeAlso annotation in the appropriate place (but don't ask me where that place is...).

I managed this with 2.0.x by creating a data binding object that includes the extra classes (in both the server and client sides):

<jaxws:server id="myServiceEndpoint"
    serviceBean="#myServiceImpl"
    serviceClass="fake.FakeImpl"
    address="/service">
  <jaxws:dataBinding>
    <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
      <property name="extraClass">
        <list>
          <value>fake.FooBar</value>
          <value>fake.AnotherSubclassOfFoo</value>
        </list>
      </property>
    </bean>
  </jaxws:dataBinding>
</jaxws:server>

For the client side, you set the data binding on the JaxWsProxyFactoryBean before calling factory.create():

JAXBDataBinding db = new JAXBDataBinding();
db.setExtraClass(new Class[] {
   fake.FooBar.class,
   fake.AnotherSubclassOfFoo.class
});
factory.setDataBinding(db);

To do the server side without Spring I guess you could use this same code snippet with a JaxWsServerFactoryBean.

Ian

--
Ian Roberts               | Department of Computer Science
[EMAIL PROTECTED]  | University of Sheffield, UK

Reply via email to