Samisa Abeysinghe in his article on PHP SOAP Extension explains how this extension can be useful in providing and consuming Web services using PHP. In the article, he details the classes of extension, two implementation models of web services, and also lists a 'Hello World with SOAP Extension'.
He explains the article under the following sections:
Introduction
Samisa explains this PHP SOAP extension can be used by PHP developers to write their own web Services, and clients to make use of the existing Web services. The SOAP extension that comes with PHP 5 is an attempt to implement the Web services stack support for PHP, he says. Unlike most other efforts to support Web services for PHP, the SOAP extension is written in C. Hence it has the advantage of speed, over the other extensions, he initiates.
He points out that SOAP extension supports the following specifications:
Classes of the Extension
He tells you about six classes implemented by this extension. He says, three of the classes are high-level classes with useful methods. These classes are SoapClient, SoapServer, and SoapFault. The other three classes are low level and do not have any methods other than their constructors. These low level classes are SoapHeader, SoapParam, and SoapVar. He gives a figure to illustrate these classes.
WSDL vs. non-WSDL Modes
He explains in Web services, there are two models of implementation—Contract First model and Code First model.
He describes that in the contract first model, a Web Service Definition Language(WSDL) file, which is an XML file that defines the service interface, is used. The WSDL file defines the interface that the service has to implement or the client has to consume. The WSDL mode of the SoapServer and SoapClient is based on this concept.
But he says, in the code first model, the code implementing the service is written first. In most cases a contract, or a WSDL, is generated out of the code. Then the client can use that WSDL, at the time of consuming the service, to take note of the interface of the service. However, the PHP 5's SOAP extension does not have provisions for generating a WSDL out of the code. To cater for this situation, the non-WSDL mode of the SoapServer and SoapClient can be used, he says.
Hello World with the SOAP Extension
In this section, he explains, how to implement services and clients both in the WSDL and non-WSDL modes. Comparatively, he says, it is easier to implement services and clients in the WSDL mode, given that a WSDL is available with the desired interface. Hence this section first describes how to implement a Web service using the WSDL mode.
In the sample Hello World service, there is an operation named ‘greet’. This operation takes a name as a string and returns a greeting as a string. He shows various code examples to facilitate the flow of the article and to explain this particular section.
He concludes by saying that the key strengths of the PHP extension include its simplicity and speed. It is simple to get a service and client up and running with the SOAP extension implemented in C. He adds that even though the SOAP extension can be very useful when dealing with simple Web services, there are limitations when considering the full Web services stack.
|