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
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 CLIENT SERVER With connection, client send HTTP request message to server POST /item HTTP/1.1 Host: Content-Type: text/plain Content-Length: 200 After processing, server send HTTP response to client 200 OK Content-Type: text/plain Content-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.1 Host: Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn IBM
SOAP example – a response HTTP/ OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn 34.5
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 definition of types definition of a message.... definition of a port definition of a binding....
WSDL example <definitions name='Catalog' targetNamespace=' xmlns:tns=' xmlns:soap=' xmlns:xsd=' xmlns:soapenc=' xmlns:wsdl=' xmlns=' …
WSDL example (cont) … <soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle=' <soap:body use='encoded' namespace='urn:localhost-catalog' encodingStyle='
SOAP/WSDL + PHP Coding time!
SOAP/WSDL + PHP SOAP/WSDL extension in PHP
MethodDescription SoapServer->__construct( mixed wsdl [, array options] ) Creates a SoapServer object. The wsdl parameter specifies the URI of the WSDL. SoapServer options such as SOAP version may be specified in the options array. SoapServer->addFunction( mixed functions ) Adds one or more PHP functions that will handle SOAP requests. A single function may be added as a string. More than one function may be added as an array. SoapServer->fault()SoapServer fault indicating an error. SoapServer->getFunctions()Returns a list of functions. SoapServer->handle() Processes a SOAP request, invokes required functions and sends back a response. SoapServer->setClass(string class_name [, mixed args [, mixed...]] ) Sets the class that will handle SOAP requests. Exports all methods from the specified class. The args are used by the default class constructor. SoapHeader->__construct()Creates a SOAP header. SoapClient->__soapCall( string function_name, array arguments [, array options [, mixed input_headers [, array &output_headers]]] ) Invokes a SOAP function. SoapClient->__doRequest()Performs a SOAP request. SoapClient->__getFunctions()Returns a list of SOAP functions. SoapClient->__getTypes()Returns a list of SOAP types.
The End