Friday, January 3, 2014

Web Service Client Using Apache CXF 2.7.0

We have developed our simple web service using apache cxf. 

For tutorials on creating web servince using apache cxf follow this tutorial

We will now see how to consume the web service in java using apache cxf . You can use any technology of your choice to consume the web service .We can use java , .net etc. Since we are using java , we will use cxf to build our client Application.


Create a dynamic web application in eclipse by going to File  , then to New , then to others and then search and click Dynamic Web project

In our example we have created a web application named as FirstWebServiceClient.
Now copy wsdl folder from FirstWebService to WebContent Folder of FirstWebServiceClient 
Now Right Click the wsdl file , then go to web service and then click on web service client

Following window will appear with default settings . Modify them as required .Change the web service runtime from apache axis to CXF since we are developing our client using apache cxf.  You can also develop you client using apache axis
Here are the settings we have made. Then Hit Next. Notice that in following screen , you can directly put the wsdl location url to generate the client else in offline mode where we dont  have url (http://localhost:3335/FirstWebService/services/WebservicePort?wsdl ) where the web service is running on , we use the wsdl file to generate our client.
Hit Next in following screen


Hit Next in following screen
In following screen Hit start server button
Hit Next in following screen
Hit Finish in following screen
Following screen in you project explorer, you can see the generated classes. The class marked in blue color is your client classes containing main method to start execution .Just open the class
Before running the class, make sure that the web service we have created is running and working.
Now run the java class marked in blue color
Following output appears after executing the class


0 comments:

Post a Comment