Consuming SOAP tutorial – Using java eclipse

Consuming SOAP tutorial from java step by step

SOAP, Simple Object Access Protocol, is older and still usable protocol for exchanging messages between systems.

Since soap is xml based, it is language and operating system independent. You can publish a soap service through your wsdl using Java on Linux and you can consume it through PHP application running on windows.

These days, SOAP is a bit lagging behind RESTful services which are rather more of architectural approaches than being protocol by themselves.

This is a tutorial showing how to consume an existing SOAP service using java language.

For this example, I will use a WSDL published on http://www.webservicex.com/globalweather.asmx?WSDL

In this one, I use already established wsdl for weather related tasks.

Eclipse has a nice tool to make life easier to consume SOAP related messages and I will show you here step by step.

Consuming SOAP tutorial step by step

1. Go ahead and create a new dynamic java project on your Eclipse

dynamic java project

java project

dynamic web project

dynamic web project



2. Give it a name of SOAPConsumption and hit finish to create the project

soap consumption tutorial

soap consumption tutorial

3. Then right click on the project and select new->->web service client

other in eclipse to select webservices

other in eclipse to select webservices

web service client

web service client

4. Click the next button
5. On the service definition enter – http://www.webservicex.com/globalweather.asmx?WSDL and hit finish

wsdl added

add wsdl

6. If everything goes well, you will see something like the following:

soap wsdl mapping

soap wsdl mapping

The above steps will create the mapping of the service locally.

Now it is time to test the service.

1. Right click on the project and create new class with package of com.gullele

test class for consumption

test class for consumption

2. Add the following code in the main method of the class.


package com.gullele;

import NET.webserviceX.www.GlobalWeatherSoapProxy;

public class TestWSClient {
	public static void main(String args[]) {
		try {
			GlobalWeatherSoapProxy proxy = new GlobalWeatherSoapProxy();
			System.out.println(proxy.getCitiesByCountry("Canada"));
		} catch (Exception ex) {
			System.out.println(ex.getMessage());
		}
	}
}

Running the above code will conclude our SOAP consumption tutorial.

As you can see, it is very intuitive to use SOAP service in the local code using eclipse.

how to get user input and process it in nodejs tutorial

how to display html files from node js example tutorial

using express package in node – installation and usage example tutorial

a hello world tutorial using node js with http web server

node js mongo db and angular js tutorial for beginners from scratch

Configuring PHP + MySQL + Apache on Amazon EC2 Step by Step

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*