Netbeans and Apache Tomcat are used in this example to make a JSP client with the help of Apache SOAP toolkit (http://axis.apache.org/axis/). Assumption here is that you are bit familiar with JSP and NetBeans. Also, Apache Xerces (http://xerces.apache.org/) is used by the Java Client. The following jars are needed to run the Java Client successfully.
b) mailapi.jar (version 1.3 or later)
c) soap.jar (version 2.1 or later)
d) xercesImpl.jar (version 2.1.1 or later)
e) xml-apis.jar (should come bundled with the Apache Xerces download)
- Click on File–>New Project –>Choose “Java Web” –>Web Application
- Provide a Project Name and Location
- Set up Server Settings and then click on “Next”
- Disregard a Web App Framework for this tutorial and click on “Finish”
- Right click “Source Packages” and select “New” Java Package
- Name the package and click on “Finish”
- Reviewing our Java Client Web Application, the directory structure should look similar to this:
- Right click the Java Web App project and select “Properties” from the menu
- In the Project Properties window select “Libraries”. Click on “Add JAR/Folder” button
- Add activation.jar, mailapi.jar, soap.jar, xercesImpl.jar, and xml-apis Libraries to the Project
- Right click the JavaClient Project and select “New” –> Web Service Client…
- Configure the Web Service Client by Adding a WSDL URL (From .Net Web Service Step #7, paste the copied URL into the “New Web Service Client” WSDL URL field. Also, specify the package we created earlier to contain the generated java artifacts that will be created.
- After clicking on “Finish”, NetBeans will output information regarding the generated java artifacts. Aim for a “BUILD SUCCESSFUL” message
- Now that our Web Service Client has been created, go to the default NetBeans Java Client Web Application start page (index.jsp in this example) and right click within thetag. Select “Web Service Client Resources” –> Call Web Service Operation…
- Select the appropriate Web Service. Here we will go with “WebService” –> WebServiceSoap –> HelloWorld
- After clicking “OK”, NetBeans will auto-generate a snippet of code and inject that code within the jsp file.
- Running the Java Client will result in a successful call to the ASP .NET C# Web Service that we constructed earlier. One can see that the Result string matches the return value of the HelloWorld() method of the ASP .NET Web Service
- The DotNetWebService.HelloWorld() Web Method returns the string value that the Java Client Web App did. Great work!
This concludes the 2012 ASP .NET C# Web Service to Java Client consumption tutorial. May your Objects, Access, and Protocols be Simple and may your Web Services be RESTful for the next episode.