Java – Axis2 web service client generation – no need to modify the type of the client

Axis2 web service client generation – no need to modify the type of the client… here is a solution to the problem.

Axis2 web service client generation – no need to modify the type of the client

Is it possible to build a Web service client using Axis2 and Eclipse and have it use a Java type already in the package instead of creating its own. The reason, of course, is that if I’ve created type A and it creates its own type A, I can’t just assign a variable of type A to a variable of type B.

WSDL is generated from a Web service that is deployed to an application server.
If you can’t generate it from it, you can generate the client from an existing java file.

Solution

If you really want to reuse an existing class, you can call the Axis2 API directly without using wsdl2java to generate a client. Here is some relatively simple code that calls a network service. You only need to fill in the web service endpoint, method QName, expected return class, and service parameters. You can reuse an existing class as a return value or parameter.

If your web service is very complex, you may find that you have to dig deeper into the API to make this approach 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);

Related Problems and Solutions