Search code examples
javacode-generationapache-axiswsdl2java

Axis2 Web Service Client Generation - Types without modifying the client


Is it possible with Axis2 and Eclipse to generate a Web Service client and have it use java types that you already have in packages instead of creating it's own types. Reason being of course if I have type A already created and it creates it's own Type A I can't just assign variable of type A to variable of type B.

The wsdl is being generated from a Web Service deployed to an application server. If it's not possible to generate it from that would it be possible to generate a client from the already existing java files.


Solution

  • If you really want to reuse existing classes, you can call the Axis2 API directly without generating a client using wsdl2java. Below is some relatively simple code to call a web service. You just need to fill in the web service endpoint, method QName, expected return Class(es), and arguments to the service. You could reuse your existing classes as the return values or arguments.

    If your web service is pretty complicated then you may find that you have to go deeper into the API to get this approach to work.

    serviceClient = new RPCServiceClient();
    Options options = serviceClient.getOptions();
    
    EndpointReference targetEPR = new EndpointReference("http://myservice");
    
    options.setTo(targetEPR);
    
    QName methodName = new QName("ns","methodName");
    
    Class<?>[] returnTypes = new Class[] { String.class };
    
    Object[] args = new Object[] { "parameter" };
    
    Object[] response = serviceClient.invokeBlocking(methodName, args,
                    returnTypes);