Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Service YU-RONG CHEN June 5 th 2014. Outline Web Service – SOAP – WSDL – UDDI – Implementation RESTful Web Service – REST – Example – Implementation.

Similar presentations


Presentation on theme: "Web Service YU-RONG CHEN June 5 th 2014. Outline Web Service – SOAP – WSDL – UDDI – Implementation RESTful Web Service – REST – Example – Implementation."— Presentation transcript:

1 Web Service YU-RONG CHEN June 5 th 2014

2 Outline Web Service – SOAP – WSDL – UDDI – Implementation RESTful Web Service – REST – Example – Implementation Comparison

3 What is a Web Service? “a method of communication between two electronic devices over the Web” – From Wiki “a software system designed to support interoperable machine-to-machine interaction over a network” – From W3C (World Wide Web Consortium)

4 Why we use web services? Interoperability Web Services take Web-applications to the next level Web Services have two types of uses – Reusable application-components – Connect existing software

5 Web Service Architecture Web Services Description Language Simple Object Access Protocol Universal Description, Discovery and Integration

6 SOAP Simple Object Access Protocol An XML based protocol for accessing Web Services. Exchanges messages between different machines. – codifies the use of XML as an encoding scheme for request and response parameters using HTTP as a means for transport.

7 `

8 WSDL Web Services Description Language WSDL is an XML-based language for describing – what a service does – where it resides – how to invoke it Characteristics of WSDL – Operations and messages are described abstractly – Defines bindings to message formats and protocols

9 WSDL document content Abstract(interface) definition: Concrete(implementation) definition ElementDescription Data type definition operation parameters abstract description of service actions set of operation definitions ElementDescription operation bindings association of an endpoint with a binding location/address for each binding

10 WSDL Example http://www.webservicex.net/globalweather.asmx?WSDL

11 Abstract data type definitions Data NameType GetWeather-ComplexType CityNameString CountryNameString GetWeatherResponse-ComplexType GetWeatherResultString GetCityByCountry-ComplexType CountryNameString GetCityByCountryReponse-ComplexType GetCityByCountryResultString

12 Data that is sent Data that is returned Message NameData type GetWeatherSoapInGetWeather GetWeatherSoapOutGetWeatherResponse GetCityByCountrySoapInGetCityByCountry GetCityByCountrySoapOutGetCityByCountryResponse GetWeatherHttpGetInCityName CountryName GetWeahterHttpGetOutBody GetCityByCountryHttpGetInCountryName GetCityByCountryHttpGetOutBody GetWeatherHttpPostInCityName CountryName GetWeatherHttpPostOutBody GetCityByCountryHttpPostInCountryName GetCityByCountryHttpPostOutBody

13 portType with operations Operations with request & response message PortType NameOperation NameDescriptionInput/Output(mesage) GlobalWeatherSoapGetWeatherGet weather report for all major cities around the world GetWeatherSoapIn/ GetWeatherSopaOut GetCityByCountryGet all major cities by country name(full/part) GetCityByCountrySoapIn/ GetCityByCountrySoapOut GlobalWeatherHttpGetGetWeatherGet weather report for all major cities around the world GetWeatherHttpGetIn/ GetWeatherHttpGetOut GetCitiesByCountryGet all major cities by country name(full / part) GetCitiesByCountryHttpGetIn/ GetCitiesByCountryHttpGetOut GlobalWeatherHttpPostGetWeatherGet weather report for all major cities around the world GetWeatherHttpPostIn/ GetWeatherHttpPostOut GetCitiesByCountryGet all major cities by country name(full / part) GetCitiesByCountryHttpPostIn/ GetCitiesByCountryHttpPostOut

14 Bind an abstract operation to this implementation and map the abstract input and output messages to these concrete messages binding NameType(portType)Operation Implementation GlobalWeatherSoap GetWeather Action:http://www.webserviceX.NET/GetWeather Style: document Input: literal Output: literal GetCitiesByCountry Action:http://www.webserviceX.NET/GetCitiesByCountry Style: document Input: literal Output: literal GlobalWeatherSoap12GlobalWeatherSoapGetWeather Action:http://www.webserviceX.NET/GetWeather Style: document Input:literal Output:literal GetCitiesByCountry Action: http://www.webserviceX.NET/GetCitiesByCountry Style: document Input: literal Output:literal

15 binding NameType(portType)Operation Impementation GlobalWeatherHttpGet Verb: Get GetWeather location:/GetWeather Input: urlEncoded Output: mime:mimeXml part="Body" GetCitiesByCountry Location:/GetCitiesByCountry Input: urlEncoded Output: mime:mimeXml part="Body" GlobalWeatherHttpPost Verb:Post GetWeather location:/GetWeather Input: mime:content type= "application/x-www-form-urlencoded"/ Output: mime:mimeXml part="Body" GetCitiesByCountry Location:/GetCitiesByCountry Input: mime:content type= "application/x-www-form-urlencoded"/ Output: mime:mimeXml part="Body"

16 Service name Network address of service Service NamePort NameBindingLocation GlobalWeather GlobalWeatherSoap http://www.webs ervicex.net/global weather.asmx GlobalWeatherSoap12 http://www.webs ervicex.net/global weather.asmx GlobalWeatherHttpGet http://www.webs ervicex.net/global weather.asmx GlobalWeatherHttpPost http://www.webs ervicex.net/global weather.asmx

17 UDDI Universal description, discovery, and integration UDDI is a registry standard for Web service description and discovery together with a registry facility that supports the WS publishing and discovery processes. UDDI enables a business to: – describe its business and its services – discover other businesses that offer desired services – integrate (interoperate) with these other businesses

18 UDDI(cont.) Conceptually, a UDDI business registration consists of three inter-related components – “white pages” (address, contact, and other key points of contact) – “yellow pages” classification info. based on standard industry taxonomies – “green pages”, the technical capabilities and information about services

19 UDDI Data Structure The UDDI XML schema defines 4 core types of information – businessEntity: a description of the organization that provides the service. – businessService: a list of all the Web services offered by the business entity. – bindingTemplate: describes the technical aspects of the service being offered. – tModel: (“technical model”) is a generic element that can be used to store technical information on how to use the service, conditions for use, guarantees, etc.

20 How to implement Soap WS? Two ways to implement: – Contract-First encourages developers to think of the service contract first, in terms of XML, using XML schema (.xsd) and WSDL – Contract-Last expose an existing service interface as a web service many tools and libraries can help expose a Java class/interface as a web service define the contract for this web service as the last step in the development process by generating it from Java code Develop Contract-Last web Service – JAVA Service Programs Development – Web Services Exposition Development – Web Services Client Development

21 Environment JDK – jdk1.7.0_17 Eclipse – Helios 7.1.1 Tomcat – apache-tomcat-7.0.37

22 Programs Development (1/4) Create Project – File  New  Dynamic Web Project

23 Programs Development (2/4) Project Name – PurchaseOrder Target runtime – Apache Tomcat

24 Programs Development (3/4) Create a Class – Package ws.com – Class WebService_purchaseOrder

25 Programs Development (4/4) Method – purchase_order_billTo Service functionality : Input two parameter: String Op1,int cash Output a String Service functionality : Input two parameter: String Op1,int cash Output a String

26 Web services Development (1/5) Create Web services Java File  Web Services  Create Web Services

27 Web services Development (2/5)

28 Web services Development (3/5) Methods

29 Web services Development (4/5)

30 Web services Development (5/5) Generate wsdl

31 WSDL

32

33 Test WSDL

34

35

36

37 Web services Client Development (1/1) New a Dynamic Web Project New a Web Service Client

38 Web services Client Development (1/4) Choose WSDL

39 Web services Client Development (2/4) Use Test Client

40 Web services Client Development (3/4) Choose output folder

41 Web services Client Development (4/4) Client Test configuration setting

42 Web services Client Test Page

43 Criticisms Too complex, not open source A custom interface requires a custom client for every service Concerns about performance due to XML and SOAP/HTTP in enveloping and transporting

44 RESTful Web Service

45 REST(REpresentational State Transfer) Introduced by Roy Fielding in his doctoral dissertation – He is one of the principal authors of the HTTP specification version 1.0 and 1.1 A software architectural style. Interact with stateful resources, rather than messages or operations Use HTTP standard operations such as GET, POST, PUT, DELETE

46 Noun(Resource) Verb(method) Representation(Content Type) Browser REST is kind of behavior to transfer the state of content type

47 REST Triangle (Resources)

48 HTTP methods MethodCRUDDescriptionExample (Verb+Resource) GETReadRetrieve a current resource representation GET http://book.com/books/1 PUTUpdateModify a resource representationPUT http://book.com/books/10 POSTCreateInitial a new resource representation POST http://book.com/books/100 DELETEDeleteClear a resource representationDELETE http://book.com/books/1

49 Architectural Elements Component – is an abstract unit of software instructions and internal state that provides a transformation of data via its interface Connector – is an abstract mechanism that mediates communication, coordination, or cooperation among components Data – is an element of information that is transferred from a component, or received by a component, via a connector

50 Architectural Constraints Client-server Stateless – Server contains no client state – Self-descriptive messages Cacheable – Clients can cache responses Layered system – Clients cannot tell whether it’s connected directly to the end server, or an intermediary Code on demand (optional) – Servers can temporarily extend or customize the functionality of a client by the transfer of executable code. Uniform interface

51 REST-Conclusion Violating any of required constraint means service is not strictly RESTful Compliance with REST constraints allows: – Scalability – Simplicity – Modifiability – Visibility – Portability – Reliability

52 RESTful Web Service A RESTFul web service is based on HTTP methods and the concept of REST is defined with these aspects: – base URI – an Internet media type for the data – standard HTTP methods(e.g., GET, PUT, POST, or DELETE)

53 RESTful WS – Example(1) Twitter API – https://dev.twitter.com/docs/api/1.1

54 RESTful WS – Example(2) Google Map API(Google Distance Matrix) – https://developers.google.com/maps/documentat ion/distancematrix/?hl=en

55 RESTful WS-Implementation(1/7) new a dynamic web project

56 RESTful WS-Implementation(2/7) Add jar files to WEB-INF/lib

57 RESTful WS-Implementation(3/7)

58 RESTful WS-Implementation(4/7) UserInfo.java Class level path in URI Verb: GET Method level path in URI Content type: XML Inject the value of URI parameter Return i

59 RESTful WS-Implementation(5/7) Add web.xml into WEB-INF

60 RESTful WS-Implementation(6/7) http://localhost:8080/RESTfulWS/rest/UserInfoService/name/YURONG

61 RESTful WS-Implementation(7/7) Creating Client - UserInfoClient.java

62 Comparison


Download ppt "Web Service YU-RONG CHEN June 5 th 2014. Outline Web Service – SOAP – WSDL – UDDI – Implementation RESTful Web Service – REST – Example – Implementation."

Similar presentations


Ads by Google