James Holladay, Mario Sweeney, Vu Tran. Web Services Presentation Web Services Theory James Holladay...

33
Web Services James Holladay, Mario Sweeney, Vu Tran

Transcript of James Holladay, Mario Sweeney, Vu Tran. Web Services Presentation Web Services Theory James Holladay...

Web Services

Web ServicesJames Holladay, Mario Sweeney, Vu TranWeb Services PresentationWeb Services TheoryJames HolladayTools Visual StudioVu TranTools Net BeansMario SweeneyWhat are Web Services (WS)?Web Services are usually APIsAccessed over a network (local or internet)Service executes on a remote host

W3C Definition A software system that:Allows interaction over a networkInterface is described in WSDLCommunication via SOAP messages, usually over HTTPWhy Web Services?Communication formats are based on XMLNot OS SpecificNot Platform - SpecificNo need to rewrite existing components (expensive!), just write the connecting codeOverview of Web Services

Requestor and Provider EntitiesRequestor entity consumes a service

Provider entity provides the service

Both provide agents that can communicate to implement a particular serviceRequestor and Provider AgentsHW / SW that send and receive messages

Requestor Agent and Provider Agent pass SOAP messages, on behalf of the Requestor Entity and Provider Entity

Web Services vs. Web ApplicationsWeb Services help turn traditional applications into web applicationsXML allows messages to be sent across applicationsUsing a Web ServiceRequester (R) and provider (P) become known to each other (UDDI or other directory)They agree on a service description and semanticsWSDLR, P use the service description and semanticsR, P agents exchange messages to perform a function for the R, P entitiesSOAP is a protocol for accessing a Web Service (via message-passing)WSDL (WS Description Language)WSDL is an XML-based languageW3C standardUsed to describe a Web ServiceMessage formatsData typesTransport ProtocolsUsed to locate a Web ServiceMay specify 1 or more network locations for invocationWSDL Structure - Data types used by a web serviceFor maximum portability, XML Schema syntax is used

- Messages used by a web serviceMessage parts are comparable to function parametersWSDL Structure (continued) - Operations performed by a web serviceComparable to a function library, module, or class

- Communication protocols used by a web serviceDefines the message format and protocol details for each portWSDL Code Snippet (w3schools.com) Like F() Like Input

Like Output

WSDL Ports Operation TypesOne-WayReceives a message; will not respondRequest-Response (most common)Receives a request; returns a responseSolicit-ResponseSends a request; waits for a responseNotificationSends a message, will not wait for a responseSOAP (Simple Object Access Protocol)Communications protocolFormat for sending messagesTransport over internet application layer (HTTP, SMTP)Platform and language independentBased on XMLA W3C standardSome SOAP Syntax RulesA SOAP message:Must be encoded using XMLMust use the SOAP Envelope namespaceMust use the SOAP Encoding namespaceCannot contain a DTD referenceCannot contain XML Processing InstructionsMust have an Envelope root element and a Body elementHeader is optional, but must be the first childSOAP StructureA SOAP message is an XML document with the following structure:An Envelope element that identifies the XMLdocument as a SOAP messageA Header element (optional) defineshow a recipient should process itA Body element that contains calland response informationA Fault element containing errorsand status information

SOAP-ENV: FaultSOAP - NamespaceThe xmlns:soap namespace is http://www.w3.org/2001/12/soap-envelopeThis defines the Envelope element as a SOAP element.

If a different namespace is used, the application:Generates an errorDiscards the messageSOAP Message Example (w3schools.com)

... Message information goes here ...

SOAP HeadermustUnderstand Attribute (0|1)Whether a header entry is mandatory or optional for a recipient to processIf a required entry cannot be processed by a recipient, header processing fails, and the service cannot be used

encodingStyle AttributeDefines data types used for the given element, its childrenNo default encoding (SOAP message body contains the actual message)SOAP Body(Request SOAP Message) Gas

(Response SOAP Message) 3.21

SOAP Fault Element (optional)Used for error messagesCan only appear once; Child of the BODY elementSub-elements:CodeReadable explanationWho?Fault code examplesClient, Server, mustUnderstand, versionMismatchHTTPTCP/IPExample request:POST /item HTTP/1.1Host: 189.123.345.239Content-Type: text/plainContent-Length: 200Example response:200 OKContent-Type: text/plainContent-Length: 200SOAP HTTP BindingSOAP: HTTP request/response with proper SOAP encodingHTTP + XML = SOAPRequest can be POST or GETContent-type is requiredSyntax: Content-Type: MIMEType; charset=character-encodingContent-length is requiredSyntax: Content-Length: bytesSOAP Example (Request)POST /InStock HTTP/1.1Host: www.mySite.comContent-Type: application/soap+xml; charset=utf-8RequiredContent-Length: nnnRequired

NS Defined Chevron Parameter

SOAP Example (Response)HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn

3.21 Parameter

UDDI (Universal Description, Discovery and Integration)A directory of web service WSDL interfacesOffers information about WSUDDI communicates via SOAPUDDI is built into the Microsoft .NET platformMarketing product awareness

Information / Image SourcesW3 (http://www.w3.org/)W3 Schools (http://w3schools.com/)http://soapuser.com/http://searchsoa.techtarget.com/tip/Demystifying-Web-services-How-they-really-workWikipediaOther tutorial sites with small snippets of informationNow Tools!Visual Studio (Vu)

Net Beans (Mario)Quick Review

Credit CardValidation

Consumer (Client)Provider(Server)Provider(Server)Provider(Server)Calculator

Provider(Server)Java ApplicationConsumer (Client)JSPConsumer (Client)Servlet ApplicationConsumer (Client)