Presentation is loading. Please wait.

Presentation is loading. Please wait.

31242/32549 Advanced Internet Programming Advanced Java Programming

Similar presentations

Presentation on theme: "31242/32549 Advanced Internet Programming Advanced Java Programming"— Presentation transcript:

1 31242/32549 Advanced Internet Programming Advanced Java Programming
Web services Intro

2 Web Applications Presentation-oriented:
PAGE based App generates Markup pages (HTML, XHTML etc) “Human oriented”: user interacts with page: Request/Response B2C & B2C Service-oriented: “web services” Service based Application provides “Remote Procedure Calls/Remote Methods” “Machine oriented”: Application interacts with Application: Request/Response (RPC) Message oriented

3 Web Services – problems solved
Before Web: Traditional approach: “Remote Procedure Calls” or “Remote Method Invocation” Tied to the underlying architecture Binary message formats Compatibility issues Proprietary technologies and implementations Expensive, Inflexible, Complex Not firewall friendly

4 Web services – problems solved
After Web: Different vendors attempted HTTP based solutions Web based RPC: Just send and receive plain text via a URL XML based RPC: Send/receive requests as XML  XML-RPC “standard” ( Language & technology neutral, but not a standard  Influenced standards  formalised as SOAP.

5 Web services - definition
“Web services are self-contained, self-describing, modular applications that can be published, located, and invoked across the web.” “Web service applications are encapsulated, loosely coupled web ‘components’ that can bind dynamically to each other.” Web Services  a distributed computing platform

6 W3C web services standard
W3C standard for web services: An application (Consumer) connects to another application (Provider) via SOAP The Consumer knows how to connect to the Provider because the interface is described with WSDL. The Consumer can find the Provider because the provider’s details are published in a UDDI registry. Both communicate using the web protocol, HTTP. The data exchange is via XML and XML Schema

7 Web Services Introduction

8 SOAP “Simple Object Access Protocol” SOAP message contains:
Envelope: describes the message and how to process it Header: contains the features of the SOAP message Body: contains the primary information for the message receiver

9 SOAP SOAP works by transmitting XML between the Consumer and Provider.
Akin to “Snail Mail” – Envelope is like the mail address, Body is like the content of the letter

10 SOAP Calls and responses are sent as SOAP Envelopes.
SOAP is a XML Message format Calls and responses are sent as SOAP Envelopes. The message in a SOAP Envelope has a header (optional) and a body. The Body is for application level data. Parameters, method calls etc. The Header is for infrastructure level data. Authentication, coordination etc. Header attributes: actor (none, next, ultimateReceiver) mustUnderstand (1 or 0)

11 getStockPrice(“IBM”)
SOAP Request Example <?xml version="1.0"?> <soap:Envelope xmlns:soap="" soap:encodingStyle=""> <soap:Body xmlns:m=""> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope> getStockPrice(“IBM”)

12 getStockPrice(“IBM”)  34.5
SOAP Request Example <?xml version="1.0"?> <soap:Envelope xmlns:soap="" soap:encodingStyle=""> <soap:Body xmlns:m=""> <m:GetStockPriceResponse> <m:Price>34.5</m:Price> </m:GetStockPriceResponse> </soap:Body> </soap:Envelope> getStockPrice(“IBM”)  34.5

13 SOAP Summary SOAP is a simple protocol intended for transferring data from one application to another. SOAP provides a mechanism for encapsulating RPC calls into SOAP messages (in envelopes). SOAP uses existing, recognised standards to solve problems of data representation and transport. Some SOAP downfalls: No mechanisms for reliability, transactions, security… SOAP is, in itself, not adequate for all needs in industrial applications Extra standards to add missing functionality include WS-reliable messaging, WS-Security WS-Coordination, WS-Transactions

14 WSDL How do you know how to invoke a web service?
SOAP only specifies the format for message exchange, it doesn’t say what the message itself should contain! What is the address of the web service? What are the required parameters? What protocols are used? Web Services Description Language (WSDL) specifies the answers to these questions

15 WSDL Structure Service: Binding: Port type: Operation: Message:
collection of endpoints endpoint = port + binding Binding: maps operations to protocols (e.g. SOAP via HTTP) Port type: a set of operations supported by endpoints (like a function library) Operation: abstract description of an action supported by a service Message: typed definition of data communication (input and output)

16 WSDL Elements <service> <port>
Groups related ports together eg. If a portType is bound to two protocols, they are grouped together <port> Specifies the location of the web service

17 WSDL Elements <service name="CalculatorService">
<port name="CalculatorPort" binding="tns:CalculatorPortBinding"> <soap:address location="http://localhost:8888/calculator"/> </port> </service>

18 WSDL Elements <binding>
Specifies protocols used to invoke web service Eg. Is this a SOAP web service? Over HTTP? The abstract interface defined in <portType> can be bound to different messaging and transport protocols Eg. SOAP over HTTP, SOAP over SMTP, …

19 WSDL Elements <binding name="CalculatorPortBinding" type="tns:Calculator"> <soap:binding transport="" style="document"/> <operation name="add"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> </output> </operation> </binding>

20 WSDL <portType> <operations>
Defines the interface (similar to Java interface definition) <operations> Defines the actions (similar to Java methods) <portType name="Calculator"> <operation name="add"> <input message="tns:add"/> <output message="tns:addResponse"/> </operation> </portType>

21 WSDL Elements <message> Defines a set of parameters
Defined messages are referred to in the <portType> element <message name="add"> <part name="parameters" element="tns:add"/> </message> <message name="addResponse"> <part name="parameters" element="tns:addResponse"/>

22 WSDL Elements <types> Defines the data types used
Referred to by <message> elements Usually uses XML schema to define types

23 WSDL Elements <types>
<xs:schema targetNamespace="http://server/"> <xs:element name="add" type="tns:add"/> <xs:complexType name="add"> <xs:sequence> <xs:element name="arg0" type="xs:int"/> <xs:element name="arg1" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:element name="addResponse“ type="tns:addResponse"/> …. & so on….

24 Agenda Introduction to Web Services
Enabling technologies: SOAP and WSDL, UDDI JAX-WS

25 JAX-RPC JAX-RPC was the older standard for interfacing web services with Java This had several flaws – not so easy to use, mainly dealt with RPC style transactions, not built into Java JAX-RPC 2.0 was a refresh & got renamed to JAX-WS

26 JAX-WS Now built into Java 6
Concept: you write POJO (Plain Old Java Objects) and annotate your code (next slides are from Sun Java user group, tech days 2008 (Carol McDonald))

27 Developing with JAX-WS

28 Writing service

29 JAX-WS mapping

30 Customising

31 Client side

32 Client


34 Labs We will develop both a server and client using JAX-WS in the labs

35 Questions? ?

Download ppt "31242/32549 Advanced Internet Programming Advanced Java Programming"

Similar presentations

Ads by Google