200 likes | 343 Views
TP2653 Adv Web Programming. SOAP and WSDL. SOAP. Simple Object Access Protocol Lightweight XML-based messaging protocol A protocol for accessing a Web Service Allows applications to exchange information over HTTP Platform/language independent A W3C recommendation (June 2003). Why SOAP?.
E N D
TP2653 Adv Web Programming SOAP and WSDL
SOAP • Simple Object Access Protocol • Lightweight XML-based messaging protocol • A protocol for accessing a Web Service • Allows applications to exchange information over HTTP • Platform/language independent • A W3C recommendation (June 2003)
Why SOAP? • Allowing internet communication between programs • Usually applications communicate using RPC (DCOM or CORBA) – causing compatibility and security problems
SOAP Building Blocks • SOAP message – XML document with: • Envelope element – identifies the XML document as a SOAP message • Header element – contains header information • Body element – contains call/response information • Fault element – contains errors/status information
SOAP message - skeleton <?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Header>...</soap:Header><soap:Body>... <soap:Fault> ... </soap:Fault></soap:Body></soap:Envelope>
Syntax Rules • SOAP message syntax rules: • Must be encoded using XML • Must be using SOAP envelope namespace • Must be using SOAP encoding namespace • Must NOT contain DTD reference • Must NOT contain Processing Instructions
SOAP - HTTP protocol • HTTP communicates over TCP/IP • HTTP client connects to HTTP server using TCP With connection, client send HTTP request message to server POST /item HTTP/1.1Host: 189.123.255.239Content-Type: text/plainContent-Length: 200 CLIENT SERVER After processing, server send HTTP response to client 200 OKContent-Type: text/plainContent-Length: 200
SOAP HTTP binding • SOAP method – HTTP request/response that complies with SOAP encoding rules • HTTP + XML = SOAP • HTTP POST or HTTP GET • HTTP POST • Content-Type – MIME type for message and character encoding • Content-Length – number of bytes in body of request/response
SOAP example – a request POST /InStock HTTP/1.1Host: www.example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Bodyxmlns:m="http://www.example.org/stock"> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice></soap:Body></soap:Envelope>
SOAP example – a response HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn<?xml version="1.0"?><soap:Envelopexmlns:soap="http://www.w3.org/2001/12/soap-envelope"soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"><soap:Bodyxmlns:m="http://www.example.org/stock"> <m:GetStockPriceResponse> <m:Price>34.5</m:Price> </m:GetStockPriceResponse></soap:Body></soap:Envelope>
WSDL • Web Services Description Language • XML-based to describe Web Services and how to access them • Is an XML file, written in XML format • A W3C recommendation (June 2007)
WSDL Structure • WSDL document describes a web service using these elements:
WSDL document – main structure <definitions> <types> definition of types........ </types> <message> definition of a message.... </message> <portType> definition of a port....... </portType> <binding> definition of a binding.... </binding></definitions>
WSDL example <?xml version ='1.0' encoding ='UTF-8' ?> <definitions name='Catalog' targetNamespace='http://example.org/catalog' xmlns:tns='http://example.org/catalog' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' xmlns='http://schemas.xmlsoap.org/wsdl/'> <message name='getCatalogRequest'> <part name='catalogId' type='xsd:string'/> </message> <message name='getCatalogResponse'> <part name='Result' type='xsd:string'/> </message> <portType name='CatalogPortType'> <operation name='getCatalogEntry'> <input message='tns:getCatalogRequest'/> <output message='tns:getCatalogResponse'/> </operation> </portType> …
WSDL example (cont) … <binding name='CatalogBinding' type='tns:CatalogPortType'> <soap:binding style='rpc‘ transport='http://schemas.xmlsoap.org/soap/http’ /> <operation name='getCatalogEntry'> <soap:operationsoapAction='urn:localhost-catalog#getCatalogEntry‘ /> <input> <soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </input> <output> <soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> </output> </operation> </binding> <service name='CatalogService'> <port name='CatalogPort' binding='CatalogBinding'> <soap:address location='http://www.ftsm.ukm.my/azraai/webservice/soap-server.php'/> </port> </service> </definitions>
Coding time! SOAP/WSDL + PHP
SOAP/WSDL + PHP • SOAP/WSDL extension in PHP