SOAP Communication SOAP Communication Protocol

Chapter 8 • Web Services 277 description name=StockQuote targetNamespace=http:example.comstockquote.wsdl xmlns:tns=http:example.comstockquote.wsdl xmlns:xsd1=http:example.comstockquote.xsd xmlns:soap=http:www.w3.org200305soap-envelope xmlns=http:www.w3.orgnswsdl types schema targetNamespace=http:example.comstockquote.xsd xmlns=http:www.w3.org2001XMLSchema element name=TradePriceRequest complexType all element name=tickerSymbol type=string all complexType element element name=TradePrice complexType all element name=price type=float all complexType element schema types message name=GetLastTradePriceInput part name=body element=xsd1:TradePriceRequest message message name=GetLastTradePriceOutput part name=body element=xsd1:TradePrice message portType name=StockQuotePortType operation name=GetLastTradePrice input message=tns:GetLastTradePriceInput output message=tns:GetLastTradePriceOutput operation portType binding name=StockQuoteSoapBinding type=tns:StockQuotePortType soap:binding style=document transport=http:schemas.xmlsoap.orgsoaphttp operation name=GetLastTradePrice soap:operation soapAction=http:example.comGetLastTradePrice input soap:body use=literal input output soap:body use=literal output operation binding Ivan Marsic • Rutgers University 278 service name=StockQuoteService documentationMy first servicedocumentation port name=StockQuotePort binding=tns:StockQuoteBinding soap:address location=http:example.comstockquote port service description

8.2.4 Binding SOAP to a Transport Protocol

The key issue in deciding how to bind SOAP to a particular transport protocol is about determining how the requirements for a Web service communication style, such as RPC vs. document, synchronous vs. asynchronous, etc. map to the capabilities of the transport protocol. In particular, we need to determine how much of the overall contextual information needed to successfully execute the Web service needs to go in the SOAP message versus in the message of the transport protocol. Figure 8-8 illustrates this issue on an HTTP example. In HTTP, context information is passed via the target URI and the SOAPAction header. In the case of SOAP, context information is passed in the SOAP header. As a communication protocol, SOAP is stateless and one-way. Although it is possible to implement statefull SOAP interactions so that the Web service maintains a session, this is not the most common scenario. HTTP Message SOAP Message SOAP body HTTP Message SOAP Message SOAP body POST alertcontrol HTTP 1.1 Content-Type: textxml; charset=utf-8 Content-Length: 581 Host: www.example.org SOAPAction: notify ...... Connection: Keep-Alive soap-env: Envelope xmlns:soap-env=http:www.w3.org200305soap-envelope xmlns:xsd=http:www.w3.org2001XMLSchema xmlns:xsi=http:www.w3.org2001XMLSchema-instance soap-env:Header ...... soap-env:Header ...... soap-env: Body a:notify xmlns:a=http:example.orgalert a:note xsi:type=xsd:string Reminder: meeting today at 11AM in Rm.601 a:note a:notify soap-env: Body Physical Communication Protocol Message Out-of-message context target URI Out-of-message context SOAPAction Logical SOAP Message In-message context header blocks SOAP Body Figure 8-8: SOAP message binding to the HTTP protocol for the SOAP message example from Listing 8-1 above. Chapter 8 • Web Services 279 When using HTTP for SOAP messages, the developer must decide which HTTP method Appendix C is appropriate to use in HTTP request messages that are exchanged between the service consumer and the Web service. Usually the choice is between GET and POST. In the context of the Web as a whole not specific to Web services, the W3C Technical Architecture Group TAG has addressed the question of when it is appropriate to use GET, versus when to use POST , in [Jacobs, 2004]. Their finding is that GET is more appropriate for safe operations such as simple queries. POST is appropriate for other types of applications where a user request has the potential to change the state of the resource or of related resources. Figure 8-8 shows the HTTP request using the POST method, which is most often used in the context of Web services. I. Jacobs Editor, “URIs, Addressability, and the use of HTTP GET and POST,” World Wide Web Consortium, 21 March 2004. Available at: http:www.w3.org2001tagdocwhenToUseGet

8.3 WSDL for Web Service Description

A Web service publishes the description of the service not the actual service code. The service customer uses the aspects of the service description to look or find a Web service. The service customer uses this description since it can exactly detail what is required by the client to bind to the Web service. Service description can be partitioned into: • Parts used to describe individual Web services. • Parts used to describe relationships between sets of Web services. Our main focus will be on the first group, describing individual Web services. The second group which describes relationships between sets of Web services will be briefly reviewed in Section 8.3.5 below. The most important language for describing individual Web services currently is the Web Services Definition Language WSDL. WSDL has a dual purpose of specifying: a the Web service interface operation names and their signatures, used in the service invocation, and b the Web service implementation network location and access mechanism for a particular instance of the Web service. The interface specifies what goes in and what comes out, regardless of where the service is located or what are its performance characteristics. This is why the Web service interface is usually referred to as the abstract part of the service specification. Conversely, the implementation specifies the service’s network location and its non-functional characteristics, such as performance, reliability, and security. This is why the Web service implementation is usually referred to as the concrete part of the service specification. This section describes how WSDL is used for describing the service interface and implementation. WSDL grammar schema is defined using XML Schema. The WSDL service description is an XML document conformant to the WSDL schema definition. WSDL provides the raw technical description of the service’s interface including what a service does, how it is accessed and where a service is located Figure 8-9. Since the Web service can be located anywhere in the network, the minimum information needed to invoke a service method is: Ivan Marsic • Rutgers University 280 1. What is the service interface, that is, what are its methods operations, method signatures, and return values? 2. Where in the network host address and port number is the service located? 3. What communication protocol does the service understand?

8.3.1 The WSDL 2.0 Building Blocks

As seen Figure 8-9, WSDL 2.0 enables the developer to separate the description of a Web service’s abstract functionality from the concrete details of how and where that functionality is offered. This separation facilitates different levels of reusability and distribution of work in the lifecycle of a Web service and the WSDL document that describes it. Different implementations of the same Web service can be made accessible using different communication protocols. Recall also that SOAP supports binding to different transport protocols, Section 8.2.4 above. The description of the endpoint’s functional capabilities is the abstract interface specification represented in WSDL by the interface element. An abstract interface can support any number of operations. An operation is defined by the set of messages that define its interface pattern. Recall that invoking an object method involves a request message passing a set of parameters or arguments as well as receiving a response message that carries the result returned by the method. The reader should recall the discussion of the RPC-style SOAP communication in Section 8.2.3 above. Also, some of the method parameters may be used to pass back the output results; these are known as in-out or out parameters. Since the operation is invoked over the network, we must specify how the forward message carries the input parameters, as well as how the feedback message carries the result and the output parameters, or error message in case of failure. WSDL description Service implementation definition Service interface definition types interface Abstract part: Concrete part: What types of messages names + data types are communicated with the service? How are the methods invoked on the service? How will the service be used on the network for a protocol? SOAP-specific details are here. Where is the service located in the network? – endpoint hosts service operation1 operation2 binding operation1 operation2 Figure 8-9: The WSDL 2.0 building blocks.