Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^288) CHAPTER 19 ■ INTRODUCTION TO WEB SERVICES WITH SOAP




encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />


encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />









The definitions tag defines a number of standard namespaces. This is where the SOAP
encoding, WSDL definitions, and XSD are referenced. The only two that you need to customize
are targetNamespace and xmlns:tns. The targetNamespace attribute means that all the child
elements will be prefixed with the provided namespace. The xmlns:tns attribute will define a
URI for this namespace to the prefix tns. The rest of the prefixes are standard and can be reused for
each WSDL file, just as you would put a DOCTYPE declaration in an HTML document.
Next, the file defines two messages, providing “parts” for each that will represent the input
and return parameters. Remember that it is important that message names end in Request or
Response, as some SOAP implementations require this naming convention to operate correctly.
The part’s entries each require a data type, which can be any valid XSD type. There are literally
dozens of XSD types, but for now, it is probably best to stick to the following list: xsd:int,
xsd:string, xsd:boolean, xsd:float, and xsd:date.
Next, the file adds a port type and provides a number of operations to define the methods
exposed by the service. The input and output attributes associate messages with the operation,
and provide the parameter and return value lists.
After that, the code creates a binding between SOAP, RPC, and the port. This is largely a
technicality, so just follow the format-replacing information where it makes sense. What this
step actually does is define that you will be using the RPC style and encoding data using SOAP.
The only thing to watch for is the soapAction attribute, which needs to be set to a unique URI.
Usually, this URI is the value for xmlns:tns plus the name of the operation.
Finally, the service element puts it all together into a web server location. Unlike the
namespace URIs, which are just unique information and not actual web resources, the address
here must be the URL to the physical PHP file that will host your SoapServer.
■Note For detailed information about WSDL, refer to the W3C note at [http://www.w3.org/TR/wsdl.](http://www.w3.org/TR/wsdl.)
McArthur_819-9.book Page 288 Friday, February 29, 2008 8:03 AM
Free download pdf