soap -
Simple Object Access Protocol
https://github.com/gnurmatova/weather-SOAP
- SOAP uses XML as communication tool
- Oriented towards exposing pieces of logic, not data
- Focused on accessing named operations, each implement some business logic through different interfaces
Soap message format
WSDL(wisdle) Web Service Description Language
- XML Document
- Interface information describing all publicly available functions
- Data type information for all message requests and message responses
- Binding information about the transport protocol to be used
- Address information for locating the specified service
Definition Example
<definitions name="HelloService"
targetNamespace="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Message Example
<message name="SayHelloRequest">
<part name="firstName" />
</message>
<message name="SayHelloResponse">
<part name="greeting" />
</message>
Port Type Example
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
Operation patterns supported by WSDL
<definitions name="HelloService"
targetNamespace="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.ecerami.com/wsdl/HelloService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Message Example
<message name="SayHelloRequest">
<part name="firstName" />
</message>
<message name="SayHelloResponse">
<part name="greeting" />
</message>
Port Type Example
<portType name="Hello_PortType">
<operation name="sayHello">
<input message="tns:SayHelloRequest"/>
<output message="tns:SayHelloResponse"/>
</operation>
</portType>
Operation patterns supported by WSDL
why Rest?
- Much simpler than SOAP in all aspects
- Permits many different data formats while SOAP permits only XML
- JSON commonly used by REST is much easier to parse and plugs in directly into JavaScript
why soap?
- SOAP may be simpler for consumption, see example
- SOAP is structured, you know exactly what the data sent around would look like, while REST is free formed and the consumer needs to have a better understanding of the data being received
- SOAP is more secure and transactional, better suited for financial services
consume a soap service
http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
the command below will generate a directory structure with classes needed to consume this service
$ wsimport http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
parsing WSDL...
[WARNING] Ignoring SOAP port "WeatherSoap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 339 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpGet": no SOAP address specified. try running wsimport with -extension switch.
line 342 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpPost": no SOAP address specified. try running wsimport with -extension switch.
line 345 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
Generating code...
Compiling code...
if you want to keep the source files, run:
$ mkdir src
$ wsimport http://wsf.cdyne.com/weatherws/weather.asmx?wsdl -keep -s src
parsing WSDL...
[WARNING] Ignoring SOAP port "WeatherSoap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 339 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpGet": no SOAP address specified. try running wsimport with -extension switch.
line 342 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpPost": no SOAP address specified. try running wsimport with -extension switch.
line 345 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
Generating code...
Compiling code...
the command below will generate a directory structure with classes needed to consume this service
$ wsimport http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
parsing WSDL...
[WARNING] Ignoring SOAP port "WeatherSoap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 339 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpGet": no SOAP address specified. try running wsimport with -extension switch.
line 342 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpPost": no SOAP address specified. try running wsimport with -extension switch.
line 345 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
Generating code...
Compiling code...
if you want to keep the source files, run:
$ mkdir src
$ wsimport http://wsf.cdyne.com/weatherws/weather.asmx?wsdl -keep -s src
parsing WSDL...
[WARNING] Ignoring SOAP port "WeatherSoap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 339 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpGet": no SOAP address specified. try running wsimport with -extension switch.
line 342 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
[WARNING] ignoring port "WeatherHttpPost": no SOAP address specified. try running wsimport with -extension switch.
line 345 of http://wsf.cdyne.com/weatherws/weather.asmx?wsdl
Generating code...
Compiling code...
where do we start?
start with the class named the same name as name attribute of wsdl:service tag
package edu.unh; import com.cdyne.ws.weatherws.*; public class TestWeatherService { public static void main(String[] args) { Weather weather = new Weather(); } } package edu.unh; import java.util.List; import com.cdyne.ws.weatherws.*; public class TestWeatherService { public static void main(String[] args) { Weather weather = new Weather(); WeatherSoap weatherSoap = weather.getWeatherSoap(); ForecastReturn fr = weatherSoap.getCityForecastByZIP("06518"); ArrayOfForecast af = fr.getForecastResult(); Listlf = af.getForecast(); for(Forecast forecast:lf){ System.out.println("_________"); System.out.println(forecast.getDate()); System.out.println("High:"+forecast.getTemperatures().getDaytimeHigh()); System.out.println("Low:"+forecast.getTemperatures().getMorningLow()); System.out.println(forecast.getDesciption()); } } }