oop iiicmu/mscf1 web services description language ...

28
OOP III CMU/MSCF 1 Web Services Description Language ttp://msdn.microsoft.com/library/default.asp url=/library/en-us/dnwebsrv/html/understandWSDL.asp otes from article by Aaron Skonnard found at

Post on 21-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 1

Web Services Description Language

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwebsrv/html/understandWSDL.asp

Notes from article by Aaron Skonnard found at

Page 2: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 2

XSDL and WSDL

• XSDL (The XML Schema Definition Language) allows us to describe the structure of an XML message

• WSDL allows us to describe message exchanges

Page 3: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 3

WSDL

• A message exchange is called an operation

• Related operations are grouped into interfaces

• A binding specifies concrete details about what goes on the wire

Page 4: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 4

WSDL

• Describes the contract between applications

• Can be automatically generated from a collection of Java or C# classes

• Can be read by utilities that generate client side stub code or server side ties

• See wscompile (Sun’s J2EE) or wsdl.exe on the Microsoft side

Page 5: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 5

WSDL Structure

<definition> <!– abstract definitions <types> <messages> <portType> <!– concrete definitions <binding> <service></definition>

Page 6: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 6

WSDL Structure

<definition> <!– Terms found in application code <types> <messages> <portType> <!– Handled by XML infrastructure <binding> <service></definition>

Page 7: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 7

WSDL Structure

<definition>

<types> - a container for XSDL Type definitions

- element names may be defined here as well

Page 8: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 8

WSDL Structure

<definition>

<types> For example, in Google’s WSDL,GoogleSearchResult is

defined as a complex type with many elements.

Page 9: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 9

WSDL Structure

<definition> <types> <message> - May have more than one part (think parameters)

- Define the input or output of an operation - RPC style messages associate a name with a type (defined above) - Document style messages associate a name with an XML element

</definition>

Page 10: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 10

WSDL Structure<definition> <types> <message> Two examples:

- In Google’s WSDL, a doGoogleSearch message is defined with many parts of basic

xsd types.

- In Google’s WSDL, a doGoogleSearchResponse message is defined

as of type GoogleSearchResult </definition>

Page 11: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 11

WSDL Structure

<definition> <types> <messages> <portType> - The definition of an interface or group of operations

- The term “portType” will be replaced with the term “interface” in WSDL 1.2 - Each operation has a name and normally specifies both input and output messages

</definition>

Page 12: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 12

WSDL Structure

<definition> <types> <messages> <portType> - For example, in Google’s WSDL, GoogleSearchPort

contains three operations. - The operation doGoogleSearch has an input message (doGoogleSearch) and an output message (doGoogleSearchResponse.)

</definition>

Page 13: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 13

WSDL Structure

<definition> <types> <messages> <portType><binding> - Each binding has a unique name that is associated with

a particular interface. - The protocol used is specified. - Details found here specify how the data will look on the wire.

</definition>

Page 14: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 14

WSDL Structure

<definition> <types> <messages> <portType><binding> - For example, in Google’s WSDL, the binding

name GoogleSearchBinding is introduced and is associated with the interface GoogleSearchPort. - Each operation within that interface is described as soap operations.

</definition>

Page 15: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 15

WSDL Structure

<definition> <types><messages><portType><binding> <service> - Defines a collection of ports (endpoints) that

exposes a particular bindind - An address is associated with a binding

</definition>

Page 16: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 16

WSDL Structure

<definition> <types><messages><portType><binding> <service> For example, in Google’s WSDL, the service

name GoogleSearchService is introduced. The interface GoogleSearchPort is associated with the binding GoogleSearchBinding. The service element holds the address of the service.

</definition>

Page 17: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 17

WSDL Message Exchange Patterns

An interface may define four types of operations:

• One-Way The endpoint receives a message.• Request-response The endpoint receives a message

and returns a message.• Solicit-response The endpoint sends a message

and receives a response.• Notification The endpoint sends a message.

Page 18: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 18

Writing A Google Client

(1) Get the WSDL from http://www.google.com/apis/

(2) Run wscompile on config.xml and generate an API from the WSDL

(3) Examine the WSDL and note the service element

<!-- Endpoint for Google Web APIs --> <service name="GoogleSearchService"> <port name="GoogleSearchPort" binding="typens:GoogleSearchBinding"> <soap:address location="http://api.google.com/search/beta2"/> </port> </service>

The API has a GoogleSearchService_Impl() class with a getGoogleSearchPort()method. The GoogleSearchPort interface implements operations like doSpellingSuggestion and doGoogleSearch.

Page 19: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 19

A Google Client

// Running a simple Google RPC client

import javax.xml.rpc.Stub;import stubcode.*;

public class MyGoogleClient{

private static String endpointAddress = "http://api.google.com/search/beta2";

Page 20: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 20

public static void main(String[] args) throws Exception {

System.out.println("Contacting Google Web Service at " + endpointAddress); Stub stub = (Stub) (new GoogleSearchService_Impl().getGoogleSearchPort());

stub._setProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);

GoogleSearchPort gsp = (GoogleSearchPort)stub; String answer = gsp.doSpellingSuggestion( "n6lHU/FQFHIHzpbzRTPFvrUP4Cw+/k+N", "buuaty"); System.out.println(answer); }}

Page 21: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 21

D:\McCarthy\www\95-702\examples\GoogleWSDLOnly>java MyGoogleClientContacting Google Web Service at http://api.google.com/search/beta2beauty

Page 22: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 22

Another simple client

Look over some web services at

http://www.capescience.com/webservices/index.shtml

Suppose we choose Airport Weather

http://www.capescience.com/webservices/airportweather/index.shtml

We need the WSDL for this service. It’s found at

http://live.capescience.com/wsdl/AirportWeather.wsdl

Page 23: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 23

Code Generation

• We will run wscompile against the WSDL• Build a simple config.xml that points to the

WSDL

<?xml version="1.0" encoding="UTF-8"?><configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config"> <wsdl location="AirportWeather.wsdl"

packageName="airport"/></configuration>

Page 24: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 24

Code Generation

• Set up for wscompile (provided with the J2EE Application server)

• Prior to running wscompile, my D:\Sun\AppServer\jdk\jre\lib\endorsed

contains the following .jar files:

activation, dom, jax-qname, jaxrpc-api, jsf-api

mail, saaj-api, saaj-impl, xalan, xercesImpl,

jaxrpc-impl.jar

Page 25: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 25

Code Generation

• Running wscompile

C:>wscompile -gen:client -keep -d airport config.xml

• Generates client side files in the airport directory and keeps the source code.

Page 26: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 26

Examine the WSDL<service name="AirportWeather">

<documentation>AirportWeather</documentation><port binding="tns:StationBinding" name="Station">

<soap:address location= "http://live.capescience.com:80/ccx/AirportWeather"/>

</port>

</service>

The API has a AirportWeather_Impl class with a getStation()method. The Station interface implements operations like getSkyConditions, getLocation, and getVisibility.

Page 27: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 27

Write a Java Clientimport airport.*;

public class Client{ public static void main (String args[]) throws Exception { AirportWeather_Impl service = new AirportWeather_Impl(); Station stub = service.getStation();

String temp = stub.getTemperature ( "KCID" );

System.out.println ( temp );

}}

Page 28: OOP IIICMU/MSCF1 Web Services Description Language  ?url=/library/en-us/dnwebsrv/html/understandWSDL.asp Notes

OOP III CMU/MSCF 28

D:\McCarthy\www\95-702\examples\AirPort>java ClientThe Temperature at Cedar Rapids, The Eastern Iowa Airport, IA, United States is46.9 F (8.3 C)

The Output