SessionBean as WebService - again complex data structures
carstenrudat Oct 16, 2007 8:58 AMHi all,
I have a SLSB and want it to be accessable through a webservice. So I write
package com.genloop.ejb.beans.service; import javax.ejb.Remote; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; @WebService @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) @Remote public interface PartnerWebService extends java.rmi.Remote{ @WebMethod public String sayHello(String hello); }
and
package com.genloop.ejb.beans.service; import java.util.Date; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.interceptor.Interceptors; import javax.jws.WebService; import org.jboss.annotation.ejb.RemoteBinding; import org.jboss.annotation.security.SecurityDomain; import com.genloop.ejb.commons.SecurityInterceptor; import com.genloop.ejb.commons.UserInterceptor; @Stateless @Remote(PartnerWebService.class) @SecurityDomain("...") @org.jboss.annotation.ejb.Clustered @RemoteBinding(jndiBinding="test/PartnerWebService/remote") @Interceptors({UserInterceptor.class, SecurityInterceptor.class}) @WebService(endpointInterface="com.genloop.ejb.beans.service.PartnerWebService", serviceName="PartnerService") public class PartnerWebServiceBean implements PartnerWebService { public String sayHello(String hello) { return hello; } }
My Client works well:
public class PartnerWSClient { public static void main(String[] args) { try { URL url = new URL("http://localhost:8080/test-ea-test-service/PartnerWebServiceBean?wsdl"); QName qname = new QName("http://service.beans.ejb.genloop.com/", "PartnerService"); ServiceFactory factory = ServiceFactory.newInstance(); Service service = factory.createService(url, qname); PartnerWebService partnerService = (PartnerWebService)service.getPort(PartnerWebService.class); System.out.println(partnerService.sayHello("test")); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ServiceException e) { e.printStackTrace(); } } }
But now, I add another mehtod:
public ComplexObject getComplexObject() { return new ComplexObject(new Date(), "test"); } ... @WebMethod public ComplexObject getComplexObject(); ... public class ComplexObject implements Serializable { protected Date date; protected String string; public ComplexObject() { } getter/setter }
No, I just get this exception:
Cannot obtain java/xml type mapping for: {http://service.beans.ejb.genloop.com/}complexObject
I use JBoss 4.2.1 and updated JBoss Web Services to version 2.0.
And my question is: What am I doing wrong? Is there any way to get user datastructures work?