Consume a Web Service with Java
As I stated before, calling a web service in .Net is easy .Â However, using a Java Web Service is a little more difficult .Â This is not because .Net is superior to Java, but instead because of the various standards that Java allows for since it is open sourced.Â In other words, Java can be extended and new standards can be developed, whereas Microsoft keeps tight control over their beloved .Net framework.
Step 1:Â Download and Install NetBeans
First you must download and Java IDE such as Netbeans , Eclipse , or Oracle’s JDeveloper .Â I have used all three and I would recommend NetBeans because I found that JDeveloper was a little behind on certian standards and Eclipse requires that you install additional plugins to allow you to develop with web services.Â However, the latest version of NetBeans (6.5 as of this writing) comes with everything you need to develop and consume web services, including a choice of embedded web servers for development.
Step 2: Create a Web Project and Web Service Client
Next, create a new Web Project by clicking File > New and selecting Web Project from the list.
Once it builds your project, you must tell NetBeans what type of project you are developing.Â You can do this by right clicking your newly created Project in the Projects pane and selecting New > Web Service Client .Â If I remember correctly, this is where a wizard will prompt you for the Web Service WSDL that you are wanting to call .
WSDL stands for Web Service Definition Language and is a document that is generated when you build a web service to tell the applications that want to use it what methods are available to use.
Step 3: Call Web Service
Once your project finishes generating the local methods for calling the external web service, you should see a tree option under your project entitled Source Packages . Open this tree item and all items below it and you should see a Java file "*.java" .Â Double click this so it opens, then right click > Web Service Client Resources > Call Web Service Operation .
Step 4: Modify and Test
Once the generation is completed, you should be able to reference the web service objects similar to the following:
WsNameOfService port =Â Â service.getWsNameOfServicePort();
tf = port.isReady();
out.println("Result: " + tf);
Enjoy and Good Luck!
Note: If your not getting the same menu items as me then you probably created the wrong project type in the first couple of steps.Â For instance, NetBeans may not allow you to create a Web Service Client in a regular Java project.Â Start over with a new project and ensure you are selecting the correct project types.
Join him as he learns and shares his experiences of marketing his own products online.
Subscribe via RSS