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.

Wednesday, June 10, 2009

Creating Apache Axis2 Web Services on MyEclipse IDE (eclipse) , Tomcat

To follow this tutorial, you need the following software and resources.
Software or Resource
Version Required
Download bundle
version 6 or
version 5
Apache Axis 2
Java EE-compliant web or application server
Tomcat web server 6.0

Downloading the Apache Axis2 WAR file
Apache Axis2 can be downloaded here. Download the WAR (Web Archive) distribution, so you do not have to build the WAR file yourself. The download is in the form of an archive file. Later you unpack the archive to your server.
Creating an Axis2 Web Service
With MyEclipse IDE (eclipse), you can create an Axis2 web service from a Java class. You can only do this from a Dynamic Web project. In this tutorial, create an Axis2 web service in that project (creating the Java class at the same time) and deploy the Axis2 web service to a server.
Testing an Axis2 Web Service
Goto ServiceWSSoapBindingImpl.java Class and put SOP(System.out.println("Testing Web Service");) inside your method.
Navigate to wsdl file "ServiceWS.wsdl" Right-click select Web Serives-->> Test With Web Service Explorer. Expand to method level and type input value. Click on Go, MyEclipse IDE (eclipse) will display output on console.
To create an Axis2 web service:
  1. Click the New Project icon or File -> New Project. The New Project wizard opens, select show All Wizards. From the Web category, select a Dynamic Web project. Click Next.
  2. Name the project AxisWS. Check that you are using the project folder name and location that you want. It is up to you whether to share the project.
  3. Select the Target Runtime as Tomcat, if not available in dropdown then click New button and select Tomcat 6x from New Server Runtime wizard. Provide the Tomcat installation directory path and also apecify the installed JRE. Click Finish, and the MyEclipse IDE (eclipse) creates the Target Runtime for Tomcat.
  4. Click on Next and continue with the Default options. Click Next to fill Context Root, Content Directory and Java Source Directory. Click Finish, and the MyEclipse IDE (eclipse) creates the Dynamic Web Project.
  5. Right-click the src node. The context menu opens. In the context menu, choose New -> Class. The New Java Class opens. Provide the package name and java class name. Click Finish, and the MyEclipse IDE (eclipse) creates the Java Class under the provided package name.
  6. Create a method with the qualified name and provide the parameters as per the requirement. Here I'm creating a method call getRequestParamFromWS() with the method signature String and the arguments as a String parameter "value".
  7. Double check the Axis, as mentioned earler it should be deployed on Tomcat which we have configured while creating the Dynamic Web Project.

  8.  
  9. Right-click on the Java Class, goto Web Services option and select Create Web Service. The Create Web Service will open a New wizard with more options. Web Service type should be "Bottom up Java bean Web Service" Service Implementation "com.sravan.ServiceWS Client type "Java Proxy" click on Next. The next screen display's the wsdl file name and the methods available under the Java Class.
  10. Select the appropriate method and Click Next. If your Tomcat server is not running, the MyEclipse IDE (eclipse) will prompt for Start server. Click for Start server, MyEclipse IDE (eclipse) will start your Tomcat server. Click Finish to complete the WSDL file creation process.
  11. Navigate to wsdl file location. Project-->> WebContent-->>wsdl-->>ServiceWS.wsdl. Right-click on wsdl file and goto Web Service option, select Generate Java Bean Skeleton option.
  12. Web Service wizard will open, Web Service type should be "Top down Java Bean Web Service", Service definitation /AxisWS/WebContent/wsdl/ServiceWS.wsdl Client type "Java Proxy". Click Next to choose skeleton folder. Click Next will lead to the auto generated code. Click Finish to complete the process.
  13. Similarly you can generate the Web Service Client code as well, by choosing the Generate Client option displayed under Web Service Java Bean Skeleton option.

  14.  
  15. Web Service is completed, you can Add Web Capabilities for this project. While adding the Web capabilities to your peoject choose Web Content folder, or you can name it as a Web Root while creating the Dynamic Project.
  16. Create an ANT file build.xml to deploy your web application on Tomcat, after deployment type http://yourip:port/AxisWS/services/AxisWS your browser will show a message like "Hi there, this is an AXIS service!".