title: Return custom object from Web services using JAX-WS
body: <p>The question is a little bit long but I wanted to supply all the information in advance</p>
  
  <p>I have the following class:</p>
  
  <pre><code>package test.api.soap.server;
  
  public class TestClassA {
  
      public TestClassA() {
  
      }
  
      public String doA() {
          System.out.println("Start doA()");
          return "In do A";
      }
  }
  </code></pre>
  
  <p>I want to expose it as web service but not directly so i created wrapper class:
      package test.api.soap.server;</p>
  
  <pre><code>import javax.jws.WebMethod;
  import javax.jws.WebService;
  
  @WebService
  public class MyClientApiV2_5 {
  
      public MyClientApiV2_5() {
  
      }
  
      @WebMethod
      public TestClassA getTestClassA() {
          return new TestClassA();
      }
  }
  </code></pre>
  
  <p>I creating the server WSDL using standard wsgen in ant task:</p>
  
  <pre><code>&lt;target name="Create-JAXWS-SOAP-Server"&gt;
      &lt;echo message="Generate SOAP server stubs" /&gt;
      &lt;exec executable="${wsgen-cmd}"&gt;
          &lt;arg value="-verbose" /&gt;
          &lt;arg value="-classpath" /&gt;
          &lt;arg value="${build}" /&gt;
          &lt;arg value="-wsdl" /&gt;
          &lt;arg value="-d" /&gt;
          &lt;arg value="${build}" /&gt;
          &lt;arg value="-r" /&gt;
          &lt;arg value="wsdl" /&gt;
          &lt;arg value="-s" /&gt;
          &lt;arg value="${src}" /&gt;
          &lt;arg value="-keep" /&gt;
          &lt;arg value="test.api.soap.server.MyClientApiV2_5" /&gt;
      &lt;/exec&gt;
  &lt;/target&gt; 
  </code></pre>
  
  <p>The out come are 2 files:
  <strong>MyClientApiV25Service.wsdl</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-. --&gt;
  &lt;definitions targetNamespace="http://server.soap.api.test/" name="MyClientApiV2_5Service" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:tns="http://server.soap.api.test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt;
    &lt;types&gt;
      &lt;xsd:schema&gt;
        &lt;xsd:import namespace="http://server.soap.api.test/" schemaLocation="MyClientApiV25Service_schema1.xsd"/&gt;
      &lt;/xsd:schema&gt;
    &lt;/types&gt;
    &lt;message name="getTestClassA"&gt;
      &lt;part name="parameters" element="tns:getTestClassA"/&gt;
    &lt;/message&gt;
    &lt;message name="getTestClassAResponse"&gt;
      &lt;part name="parameters" element="tns:getTestClassAResponse"/&gt;
    &lt;/message&gt;
    &lt;portType name="MyClientApiV2_5"&gt;
      &lt;operation name="getTestClassA"&gt;
        &lt;input wsam:Action="http://server.soap.api.test/MyClientApiV2_5/getTestClassARequest" message="tns:getTestClassA"/&gt;
        &lt;output wsam:Action="http://server.soap.api.test/MyClientApiV2_5/getTestClassAResponse" message="tns:getTestClassAResponse"/&gt;
      &lt;/operation&gt;
    &lt;/portType&gt;
    &lt;binding name="MyClientApiV2_5PortBinding" type="tns:MyClientApiV2_5"&gt;
      &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/&gt;
      &lt;operation name="getTestClassA"&gt;
        &lt;soap:operation soapAction=""/&gt;
        &lt;input&gt;
          &lt;soap:body use="literal"/&gt;
        &lt;/input&gt;
        &lt;output&gt;
          &lt;soap:body use="literal"/&gt;
        &lt;/output&gt;
      &lt;/operation&gt;
    &lt;/binding&gt;
    &lt;service name="MyClientApiV2_5Service"&gt;
      &lt;port name="MyClientApiV2_5Port" binding="tns:MyClientApiV2_5PortBinding"&gt;
        &lt;soap:address location="REPLACE_WITH_ACTUAL_URL"/&gt;
      &lt;/port&gt;
    &lt;/service&gt;
  &lt;/definitions&gt;
  </code></pre>
  
  <p><strong>MyClientApiV25Service_schema1.xsd</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;xs:schema version="1.0" targetNamespace="http://server.soap.api.test/" xmlns:tns="http://server.soap.api.test/" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="getTestClassA" type="tns:getTestClassA"/&gt;
    &lt;xs:element name="getTestClassAResponse" type="tns:getTestClassAResponse"/&gt;
    &lt;xs:complexType name="getTestClassA"&gt;
      &lt;xs:sequence/&gt;
    &lt;/xs:complexType&gt;
    &lt;xs:complexType name="getTestClassAResponse"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="return" type="tns:testClassA" minOccurs="0"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    &lt;xs:complexType name="testClassA"&gt;
      &lt;xs:sequence/&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I created the client stub:</p>
  
  <pre><code>&lt;target name="Create-JAXWS-SOAP-Client" &gt;
      &lt;echo message="Generate SOAP client stubs" /&gt;
      &lt;exec executable="${wsimport-cmd}"&gt;
          &lt;arg value="-verbose" /&gt;
          &lt;arg value="-keep" /&gt;
          &lt;arg value="-s" /&gt;
          &lt;arg value="${src}" /&gt;
          &lt;arg value="-d" /&gt;
          &lt;arg value="${build}" /&gt;
          &lt;arg value="-p" /&gt;
          &lt;arg value="test.api.soap.client.stubs" /&gt;
          &lt;arg value="wsdl\MyClientApiV25Service.wsdl" /&gt;
      &lt;/exec&gt;
  &lt;/target&gt; 
  </code></pre>
  
  <p>I then write simple client class to get the web service:</p>
  
  <pre><code>package test.api.soap.client;
  
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import javax.xml.namespace.QName;
  
  import test.api.soap.client.stubs.MyClientApiV25;
  import test.api.soap.client.stubs.MyClientApiV25Service;
  import test.api.soap.client.stubs.TestClassA;
  
  public class SampleClient {
  
      private MyClientApiV25         api         = null;
      static MyClientApiV25Service service;
  
      public SampleClient() throws MalformedURLException {
          api = service.getMyClientApiV25Port();
  
          TestClassA testClass = api.getTestClassA();
          testClass.doA();
      }
  }
  </code></pre>
  
  <p><strong>The problem is</strong>:
  Writing testClass.doA(); returns: </p>
  
  <blockquote>
    <p>The method doA() is undefined for the type TestClassA</p>
  </blockquote>
  
  <p>Any suggestions?</p>