Understant What & Why use Web Service.
Know some type of Architectural Models.
Understant Web Service Architecture.
Determine Service-Oriented Architecture
Understant and use some Web Service technologies.
Build a Simple Web Service.
167 trang |
Chia sẻ: NamTDH | Lượt xem: 1321 | Lượt tải: 0
Bạn đang xem trước 20 trang nội dung tài liệu Web Services, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
formation through decentralized and distributed environments. WSDL is an integral part of UDDI that was developed jointly by Microsoft and IBM. It defines what services are available in its Web service and also defines the methods, parameter names, parameter data types, and return data types for the Web service. The WSDL document is quite reliable and applications that use web services accept it. 8.2.2 WSDL Architecture "Web Services Description Language (WSDL) provides a model and an XML format for describing Web services.” w3c.org WSDL Types Messages Operations Port Type Binding Port Service 8.2.2 WSDL Architecture 8.2.2.1 WSDL: Types A container for data type definitions using some type system 8.2.2.2 WSDL: Messages 8.2.2.3 WSDL: Operations 8.2.2.4 WSDL: Port Types 8.2.2.4 WSDL: Port Types : Encoding 8.2.2.5 WSDL: Binding 8.2.2.6 WSDL: Port 8.2.2.7 WSDL: Service 8.3 PACKAGING SOAP Used to mean: Simple Object Access Protocol. From SOAP 1.2 > SOAP is no longer an acronym. Two Types of SOAP SOAP RPC: encode and bind data structures into xml. encode an RPC call. SOAP ‘document style’ packages xml in an envelope 8.3.1 Simple Object Access Protocol (SOAP) SOAP is a simple XML-based protocol that allows to communicate applications information over HTTP without the dependency of OS platform. SOAP uses HTTP and XML as the mechanisms for information exchange. SOAP is a lightweight protocol for exchanging structured information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined datatypes, and a convention for representing remote procedure calls and responses. 8.3.2 HTTP Web Service Request The figure shows the process for accessing a Web service using an HTTP request. HTTP Web service Request 8.3.3 SOAP Web Service Request The figure shows the process for accessing a Web service using a SOAP request. SOAP Web service Request 8.3.4 SOAP Request POST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn IBM A SOAP request: 8.3.5 SOAP Response HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn 34.5 The SOAP response: 8.3.6 SOAP Process 8.3.7 SOAP Implementation 8.3.8 SOAP Structures SOAP messages consist of Envelope: top element of XML message (required) Header: general information on message such as security (optional) Body: data exchanged (required) Header elements are application-specific may be processed and changed by intermediaries or recipient Body elements are application-specific processed by recipient only 8.3.9 SOAP Example Example: SOAP Message 8.3.10 SOAP: Serialization 8.3.10 SOAP: Serialization class PurchaseOrder { String item = "socks"; int amount = 1; } Serialization 8.3.11 SOAP RPC Encapsulate RPC into SOAP messages procedure name and arguments response (return value) processing instructions (transactional RPC!) Example: Request message 8.3.11 SOAP RPC Example: Response message 8.4 TRANSPORT HTTP POST is most common But other protocols such as FTP SMTP HTTP GET And other exotic ones: Jabber BEEP 8.4.1 Protocol Binding Bindings to different protocols possible: HTTP, SMTP Different HTTP bindings: HTTP POST, HTTP GET Standard HTPP POST for request-response 9. Web Services Implementation 9.1 Web Services Overview 9.2 Web Services Implementation Application Server (web service-enabled) provides implementation of services and exposes it through WSDL/SOAP implementation in Java, as EJB, as .NET (C#) etc. SOAP server implements the SOAP protocol HTTP server standard Web server SOAP client implements the SOAP protocol on the client site 9.3 Three Basis of Web Services 9.4 Concepts Web Services Interaction 9.5 Styles of use Web services are a set of tools that can be used in a number of ways. The three most common styles of use are RPC, SOA and REST. Remote procedure calls Service-oriented architecture Representational state transfer (REST) 9.5.1 Remote Procedure Calls (RPC) RPC Web services present a distributed function (or method) call interface that is familiar with many developers. Typically, the basic unit of RPC Web services is the WSDL operation. The first Web services tools were focused on RPC, and as a result this style is widely deployed and supported. However, it is sometimes criticized for not being loosely coupled, because it was often implemented by mapping services directly to language-specific functions or method calls. Many vendors felt this approach to be a dead end, and pushed for RPC to be disallowed in the WS-I Basic Profile. Other approaches with nearly the same functionality as RPC are Object Management Group's (OMG) Common Object Request Broker Architecture (CORBA), Microsoft's Distributed Component Object Model (DCOM) or Sun Microsystems's Java/Remote Method Invocation (RMI). 9.5.2 Service-oriented architecture Web services can also be used to implement an architecture according to Service-oriented architecture (SOA) concepts. The basic unit of communication is a message. This is often referred to as "message-oriented" services. SOA Web services are supported by most major software vendors and industry analysts. Middleware Analysts use Enterprise Service Buses which combine message-oriented processing and Web Services to create an Event-driven SOA. One example of an open-source ESB is Mule, another one is Open ESB. 9.5.3 Representational state transfer (REST) REST attempts to describe architectures which use HTTP or similar protocols by constraining the interface to a set of well-known, standard operations (like GET, POST, PUT, DELETE for HTTP). Here, the focus is on interacting with stateful resources, rather than messages or operations. An architecture based on REST (one that is 'RESTful') can use WSDL to describe SOAP messaging over HTTP, can be implemented as an abstraction purely on top of SOAP (e.g., WS-Transfer), or can be created without using SOAP at all. WSDL version 2.0 offers support for binding to all the HTTP request methods (not only GET and POST as in version 1.1) so it enables a better implementation of RESTful Web services.[6] However, support for this specification is still poor in software development kits, which often offer tools only for WSDL 1.1. 10. RMI vs Web Services 10.1 RMI Review The Java Remote Method Invocation (RMI) system allows an object running in one Java virtual machine to invoke methods on an object running in another Java virtual machine. RMI provides for remote communication between programs written in the Java programming language. RMI provides the mechanism by which the server and the client communicate and pass information back and forth. 10.2 RMI: Distributed Object Applications Distributed object applications need to do the following Locate remote objects. Applications can use various mechanisms to obtain references to remote objects. For example, an application can register its remote objects with RMI's simple naming facility, the RMI registry. Alternatively, an application can pass and return remote object references as part of other remote invocations. Communicate with remote objects. Details of communication between remote objects are handled by RMI. To the programmer, remote communication looks similar to regular Java method invocations. Load class definitions for objects that are passed around. Because RMI enables objects to be passed back and forth, it provides mechanisms for loading an object's class definitions as well as for transmitting an object's data. 10.3 RMI Stack 10.4 RMI Architecture 10.5 RMI Example 10.6 RMI vs Web Service 11. Web Service Technologies 11. Web Services Technologies 11.1 JAXB 11.1 JAXB The Extensible Markup Language (XML) and Java technology are natural partners in helping developers exchange data and programs across the Internet. How do you access and use an XML document? Simple API for XML (SAX) Document Object Model (DOM) In the SAX approach, the parser starts at the beginning of the document and passes each piece of the document to the application in the sequence it finds it. Nothing is saved in memory. In the DOM approach, the parser creates a tree of objects that represents the content and organization of data in the document. In this case, the tree exists in memory. Java API for XML Processing (JAXP) 11.1 JAXB: Accessing an XML Document Suppose you took the SAX approach. In that case, you would need to: Write a program that creates a SAX parser and then uses that parser to parse the XML document. The SAX parser starts at the beginning of the document. When it encounters something significant (in SAX terms, an "event") such as the start of an XML tag, or the text inside of a tag, it makes that data available to the calling application. Create a content handler that defines the methods to be notified by the parser when it encounters an event. These methods, known as callback methods, take the appropriate action on the data they receive. 11.1: JAXB: Use JAXB to access an XML document Let's look at how you use JAXB to access an XML document such as books.xml and display its data. Using JAXB, you would: Bind the schema for the XML document. Unmarshal the document into Java content objects. The Java content objects represent the content and organization of the XML document, and are directly available to your program. 11.1 JAXB: Unmarshal the Document Unmarshalling an XML document means creating a tree of content objects that represents the content and organization of the document. The content tree is not a DOM-based tree. In fact, content trees produced through JAXB can be more efficient in terms of memory use than DOM-based trees. 11.1 JAXB: Marshal the Content Tree Marshalling is the opposite of unmarshalling. It creates an XML document from a content tree. 11.2 JAX-RPC JAX-RPC is for Web services interoperability across heterogeneous platforms and languages. This makes JAX-RPC a key technology for Web services integration. The standard JAX-RPC programming model to develop Web service clients and endpoints based on SOAP 1.1. JAX-RPC requires SOAP and WSDL standards for this cross-platform interoperability. You can use the RPC programming model to develop Web service clients and endpoints. JAX-RPC provides support for WSDL-to-Java and Java-to-WSDL mapping. JAX-RPC enables a Web service endpoint to be developed using either a Java Servlet or Enterprise JavaBeans (EJB) component model 11.2 JAX-RPC These endpoints are described using a WSDL document. A client uses this WSDL document and invokes the Web service endpoint. A JAX-RPC client can use stubs-based, dynamic proxy or dynamic invocation interface (DII) programming models to invoke a heterogeneous Web service endpoint. 11.3 JAXM JAXM is a Java API for XML-based Messaging JAXM is designed to hide the complexity of SOAP When you use JAXM, you don't explicitly code a SOAP request. Messaging Process JAXM converts the request to a SOAP message and then transports it to the server. The server converts the SOAP message and then processes it. Then the sequence is reversed. The server converts the response to a SOAP message and transports it back to the client. 11.3 JAXM There are two roles that can take part in JAXM messaging: clients and providers. JAXM client is necessary for messaging JAXM provider is optional. JAXM client is an application that sends messages using the JAXM API. If a provider isn't used, the client sends the message to a recipient (typically a service) on a server, identified by a URL. 11.3 JAXM JAXM provider (also called a messaging provider) is an intermediate service that acts on behalf of a client. If a JAXM provider is used, the client sends the message to the provider, which then transmits and routes the message to the service. To do this, a JAXM provider implements and supports the JAXM API. 11.3 JAXM A client or client-provider pair can also receive messages can be a target service of a message. 11.3 JAXM - Asynchronous An asynchronous exchange is a one-way exchange between a sender and receiver. In an asynchronous exchange, the sender sends a message to the receiver without waiting for a response. The sender can then continue processing. When the receiver receives the message, it must process it. 11.3 JAXM - Synchronous A synchronous exchange is a two-way exchange (request-response exchange) between a client and a service or a sender and receiver. In a synchronous exchange, the client or sender sends a message to the receiver and then waits for a response. The client or sender is blocked, it can't continue processing until the service or receiver replies. 11.4 HTTP 11.5 SOAP 11.6 XML 11.7 URI 12. Web Service Security 12. Web Service Security (Project Assignment) Document: Requirement: Understand clearly about Web Service Security Components. How to sign SOAP messages to assure integrity (non-repudiation) How to encrypt SOAP messages to assure confidentiality. How to attach security tokens. 13. Building A Simple Web Service 13.1 Building Web Service with Axis2 Lab "J2EE-WebService-WebServiceWithAxis2.doc" 13.2 Building Web Service with JAX-WS Lab "J2EE-WebService-WebServiceWithJAX-WS.doc" 13.3 Building Web Service with JBoss-WS Lab "J2EE-WebService-WebServiceWithJBossWS.doc" 13.4 Building RESTful Web Service TAKE A REST HỎI ĐÁP
Các file đính kèm theo tài liệu này:
- ch07_webservices_3271.ppt