In response to the community clamor for Web Services–enabled applications, and the popularity of third-party SOAP extensions, a native SOAP extension was available as of PHP 5, and enabled by default as of PHP 6.0. This section introduces this object-oriented extension and shows you how to create both a SOAP client and server. Along the way you’ll learn more about many of the functions and methods available through this extension. Before you can follow along with the accompanying examples, you need to take care of a few prerequisites, which are discussed next. Prerequisites PHP’s SOAP extension requires the GNOME XML library. You can download the latest stablelibxml2package fromhttp://www.xmlsoft.org/. Binaries are also available for the Windows platform. Version 2.5.4 or greater is required. If you’re running a version of PHP older than 6.0, you’ll also need to configure PHP with the--enable-soapextension. On Windows, you’ll need to add the following line to yourphp.inifile: extension=php_soap.dll Instantiating the Client The SoapClient() constructor instantiates a new instance of the SoapClient class. The prototype looks like this: object SoapClient->SoapClient(mixed wsdl [, array options]) Thewsdlparameter determines whether the class will be invoked in WSDL or non-WSDL mode; if in WSDL mode, set it to the WSDL file URI, otherwise set it toNULL. Theoptionsparameter is an array that accepts the following parameters. It’s optional for WSDL mode and requires that at least thelocationandurl options are set when in non-WSDL mode:
Establishing a connection to a Web Service is trivial. The following example shows you how to use theSoapClientobject to connect to a sports-related Web service I’ve created to retrieve a random boxing quote: <?php However, just referencing the Web Service really doesn’t do you much good. You’ll want to learn more about the methods exposed by this Web Service. Of course, you can open up the WSDL document in the browser or a WSDL viewer by navigating tohttp://www.wjgilmore.com/boxing.wsdl. However, you can also retrieve the methods programmatically using the__getFunctions()method, introduced next. Please check back for the conclusion to this series.
blog comments powered by Disqus |