Bài giảng Lập trình mạng 2 - Web services - Nguyễn Xuân Vinh
Tóm tắt Bài giảng Lập trình mạng 2 - Web services - Nguyễn Xuân Vinh: ...tem and interface hierarchy between the object and the program that uses it.4. Distributed Computing ModelThe following defining properties are commonly used:There are several autonomous computational entities, each of which has its own local memory.The entities communicate with each other by messag...he interface, the location and access information.Implementation-independence Service interface available independent of the ultimate implementationPublishedSearchable service repositories of service descriptions7. Web Services Architecture1Introduction.2Why use Web Service.3Architectural Models.4Di...ries: These are the UDDI and ebXML actual registry data.Furthermore, visit DESCRIPTION WSDL OverviewWeb Services Description Language, is an XML based protocol used for sending and receiving the information through decentralized and distributed environments.WSDL is an integral part of UDDI that wa...
ist themselves on the Internet and discover each other.It defines a registry service – a Web service that manages information about service providers, service implementations, and service metadata – for Web services and for other electronic and non-electronic services.A UDDI Server acts as a registry for Web Services and makes them searchable.Provides a standardized method for publishing and discovering information about web services.The service providers can use UDDI to advertise the services they offer while service consumers can use UDDI to discover services.8.1.1 UDDI - OverviewA business can register three types of information into a UDDI registry. They provide a good summary of what UDDI can store for a business: White pages Basic contact information and identifiers about a company, including business name, address, contact information, and unique identifiers such as D-U-N-S numbers or tax IDs.Yellow pages Information that describes a web service using different categorizations (taxonomies). This information allows others to discover your web service based upon its categorization (such as being in the manufacturing or car sales business). Green pages Technical information that describes the behaviors and supported functions of a web service hosted by your business. Includes pointers to the grouping information of web services and where the web services are located. 1.1 UDDI - OverviewThe UDDI information model contains four core elements:Business information: This is described using the businessEntity element, which represents a physical organization. It contains information (such as name, description, and contacts) about the organization. The businessEntity information includes support for Yellow PagesService information: This is described using the businessService element, which groups together related services offered by an organization.Binding information: This is described using the bindingTemplate element, for information that is relevant for application programs that need to connect to and then communicate with a remote Web service. e. In other words, it provides instructions on how to invoke a remote Web servic The instructions may either be in the form of an interface definition language such as WSDL, or a text-based document.Information about specifications for services: This is described using the tModel element, which is an abstract representation of the technical specification. A tModel has a name, publishing organization, and URL pointers to the actual specifications themselves.8.1.2 UDDI SpecificationsThe UDDI defines a set of XML Schema definitions that describe the data formats used by the various specification APIs.UDDI replication This document describes the data replication processes and interfaces to which a registry operator must conform to achieve data replication between sitesUDDI operators This document outlines the behavior and operational parameters required by UDDI node operators. This specification defines data management requirements to which operators must adhereUDDI Programmer's API This specification defines a set of functions that all UDDI registries support for inquiring about services hosted in a registry and for publishing information about a business or a service to a registryUDDI data structures This specification covers the specifics of the XML structures contained within the SOAP messages defined by the UDDI Programmer's API.8.1.3 UDDI Java-Based APIs The UDDI specifications do not directly define a Java-based API for accessing a UDDI registry.The Programmer's API specification only defines a series of SOAP messages that a UDDI registry can accept.Thus, a Java developer who wishes to access a UDDI registry can do so in a number of ways:Using a Java-based SOAP API A Java programmer can use an API that creates SOAP messages containing a UDDI XML documentUsing a custom Java-based UDDI client API Some companies, such as Systinet, have created client APIs for accessing a UDDI registryUsing JAXR (Java API for XML Registries) The JAXR specification defines a standardized way for Java programs to access a registry8.1.4 UDDI - JAXR8.1.4 UDDI - JAXRThe different layers of the JAXR architecture are:JAXR Client: An application that uses the JAXR API to access a registry via a JAXR provider.JAXR Provider: An implementation of the JAXR API. The JAXR provider is pluggable in the sense that it implements the JAXR API independent of any specific registry, which provides a single abstraction for multiple registry-specific JAXR providers. It also exposes capability-specific interfaces for life cycle and query management.Registry Providers: Implementations of various registry specifications such as UDDI and the ebXML Registry.Registries: These are the UDDI and ebXML actual registry data.Furthermore, visit DESCRIPTION WSDL OverviewWeb Services Description Language, is an XML based protocol used for sending and receiving the information 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.orgWSDLTypesMessagesOperationsPort TypeBindingPortService WSDL Architecture8.2.2.1 WSDL: Types A container for data type definitions using some type system8.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 SOAPUsed to mean: Simple Object Access Protocol.From SOAP 1.2 > SOAP is no longer an acronym.Two Types of SOAPSOAP RPC:encode and bind data structures into xml.encode an RPC call.SOAP ‘document style’packages xml in an envelope8.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 RequestThe figure shows the process for accessing a Web service using an HTTP request.HTTP Web service Request8.3.3 SOAP Web Service RequestThe figure shows the process for accessing a Web service using a SOAP request.SOAP Web service Request8.3.4 SOAP RequestPOST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn IBM A SOAP request:8.3.5 SOAP ResponseHTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn 34.5 The SOAP response:8.3.6 SOAP Process8.3.7 SOAP Implementation8.3.8 SOAP StructuresHTTP PostSOAP EnvelopeSOAP HeadSOAP BodySOAP messages consist ofEnvelope: top element of XML message (required)Header: general information on message such as security (optional)Body: data exchanged (required)Headerelements are application-specificmay be processed and changedby intermediaries or recipientBodyelements are application-specificprocessed by recipient only8.3.9 SOAP ExampleExample: SOAP Message8.3.10 SOAP: Serialization8.3.10 SOAP: Serializationclass PurchaseOrder { String item = "socks"; int amount = 1;} socks 1Serialization8.3.11 SOAP RPCEncapsulate RPC into SOAP messagesprocedure name and argumentsresponse (return value)processing instructions (transactional RPC!)Example: Request message8.3.11 SOAP RPCExample: Response message8.4 TRANSPORTHTTP POST is most commonBut other protocols such asFTPSMTPHTTP GETAnd other exotic ones:JabberBEEP8.4.1 Protocol BindingBindings to different protocols possible: HTTP, SMTPDifferent HTTP bindings: HTTP POST, HTTP GETStandard HTPP POST for request-response9. Web Services Implementation1Introduction.2Why use Web Service.3Architectural Models.4Distributed Computing Model.5Service-Oriented Architecture.6Web Services Design Principles.7Web Services Architecture.8Web Services Components.9Web Service Implementation.10RMI vs Web Services.11Web Services Technologies.12Web Service Security.13Building A Simple Web Service9.1 Web Services Overview9.2 Web Services ImplementationApplication Server (web service-enabled)provides implementation of services and exposes it through WSDL/SOAPimplementation in Java, as EJB, as .NET (C#) etc.SOAP serverimplements the SOAP protocolHTTP serverstandard Web serverSOAP clientimplements the SOAP protocol on the client site9.3 Three Basis of Web ServicesWEB SERVICESHTTPSOAPXML9.4 Concepts Web Services Interaction9.5 Styles of useWeb 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 callsService-oriented architectureRepresentational 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 architectureWeb 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 Services1Introduction.2Why use Web Service.3Architectural Models.4Distributed Computing Model.5Service-Oriented Architecture.6Web Services Design Principles.7Web Services Architecture.8Web Services Components.9Web Service Implementation.10RMI vs Web Services.11Web Services Technologies.12Web Service Security.13Building A Simple Web Service10.1 RMI ReviewThe 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 ApplicationsDistributed object applications need to do the followingLocate 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 Stack10.4 RMI Architecture10.5 RMI Example10.6 RMI vs Web Service11. Web Service Technologies1Introduction.2Why use Web Service.3Architectural Models.4Distributed Computing Model.5Service-Oriented Architecture.6Web Services Design Principles.7Web Services Architecture.8Web Services Components.9Web Service Implementation.10RMI vs Web Services.11Web Services Technologies.12Web Service Security.13Building A Simple Web Service11. Web Services Technologies11.1 JAXB11.1 JAXBThe 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 DocumentSuppose 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 DocumentUnmarshalling 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 TreeMarshalling is the opposite of unmarshalling. It creates an XML document from a content tree.11.2 JAX-RPCJAX-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 model11.2 JAX-RPCThese 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 JAXMJAXM is a Java API for XML-based MessagingJAXM is designed to hide the complexity of SOAPWhen you use JAXM, you don't explicitly code a SOAP request.Messaging ProcessJAXM 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 JAXMThere are two roles that can take part in JAXM messaging: clients and providers.JAXM client is necessary for messagingJAXM 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 JAXMJAXM 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 JAXMA client or client-provider pair can also receive messages can be a target service of a message.11.3 JAXM - AsynchronousAn 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 - SynchronousA 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 HTTP11.5 SOAPHTTP PostSOAP EnvelopeSOAP HeadSOAP Body11.6 XML11.7 URI12. Web Service Security1Introduction.2Why use Web Service.3Architectural Models.4Distributed Computing Model.5Service-Oriented Architecture.6Web Services Design Principles.7Web Services Architecture.8Web Services Components.9Web Service Implementation.10RMI vs Web Services.11Web Services Technologies.12Web Service Security.13Building A Simple Web Service12. Web Service Security (Project Assignment)Document: 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 Service1Introduction.2Why use Web Service.3Architectural Models.4Distributed Computing Model.5Service-Oriented Architecture.6Web Services Design Principles.7Web Services Architecture.8Web Services Components.9Web Service Implementation.10RMI vs Web Services.11Web Services Technologies.12Web Service Security.13Building A Simple Web Service13.1 Building Web Service with Axis2Lab "J2EE-WebService-WebServiceWithAxis2.doc"13.2 Building Web Service with JAX-WSLab "J2EE-WebService-WebServiceWithJAX-WS.doc"13.3 Building Web Service with JBoss-WSLab "J2EE-WebService-WebServiceWithJBossWS.doc"13.4 Building RESTful Web ServiceTAKE A RESTHỎI ĐÁP
File đính kèm:
- bai_giang_lap_trinh_mang_2_web_services_nguyen_xuan_vinh.ppt