Latest Entries »

Friday, June 26, 2009

Create Axis web service client for the remotely exposed web service

Create Axis web service client from the wsdl file is relatively easier than creating a Axis web service client from the remote web service.


How to create Axis web service from the wsdl file:










To create Axis web services please follow my previous article, after completing the web service creation. Go to WebRoot or WebContent folder select the generated wsdl file and right click to view “Generate Client” option. This “Generate Client” option will auto generates the required code for the web service client.



How to create Axis web service client / consuming Axis web service from a remote web service:


To create Axis client for the remote web service, we need to have the following information.


  1. URL required to retrive the wsdl from the web service.

Ex: https://abcde.abcdefghijk.com/secure/cgi-bin/thisismyConfirmWs.exe/wsdl/IthisismyConfirmWs

https://abcde.abcdefghijk.com/secure/cgi-bin/thisismyConfirmWs.exe/soap/thisismyConfirmWs


2. Method to use:

The method name is required to specify the operation name, and the method signature. For example the web service exposed uses a method called getResponse(), and it accepts the arguments like String value. [getResponse(String value)].


The web service provider will mention that which type of inputs will be consumed by this web service, and the possible errors this web service will generate.

In success case what kind of parameter it will return and in failure case what kind of return parameter will be sent.


If you have all the above mentioned information available with you then you can go ahead to create a web service client for the exposed web service.


Here is the sample code:


System.out.println(domString);

String endpoint = "https://abcde.abcdefghijk.com/secure/cgi-bin/thisismyConfirmWs.exe/soap/thisismyConfirmWs";

Service service = new Service();

Call callOne = (Call) service.createCall();

callOne.setTargetEndpointAddress(new java.net.URL(endpoint));

callOne.setOperationName(new QName("avm:thisismyConfirmWsIntf-thisismyConfirmWs","getResponse());

callOne.addParameter("value", org.apache.axis.Constants.XSD_STRING, avax.xml.rpc.ParameterMode.IN);

callOne.setReturnType(org.apache.axis.Constants.XSD_STRING);

String responseWS = (String) callOne.invoke(new Object[] { domString });

System.out.println(responseWS);



In the above code example domString represents input parameter and the responseWS represents the output response we will get from the web service.

0 comments: