Build web services using Zend_Soap

| posted in: Zend Framework | 0


Description: A web service is a software system designed for interoperable interaction over a network. A web service is defined with a WSDL (Web Services Description Language) document, and other systems interact with the web service using SOAP messages.
A provider entity provides the functionality of a web service with a provider agent and a requester entity uses the web service functionality with a requester agent.

Web services implement various technologies, some of which are XML, SOAP, and WSDL.

–   XML is a standard format for data exchange. Web service requests and responses are sent as XML messages. The elements and attributes that may be specified in an XML document are specified in an XML Schema.

–   SOAP provides a standard framework for packaging and exchanging XML messages.

–   WSDL is an XML document in the namespace for describing a web service. A WSDL document specifies the operations (methods) provided by a web service and the format of the XML messages.
Installing the PHP Web Services Extensions

To enable the SOAP and XML-RPC extensions add the following extension directives in the php.ini configuration file



The SOAP extension supports subsets of the SOAP 1.1, SOAP 1.2, and WSDL 1.1 specifications.

Creating a SOAP Web Service

After activating the SOAP extension in the PHP configuration file, a SOAP server and a SOAP client may be created using the Zend_Soap class. A SOAP server serves web service requests and a SOAP client invokes methods on the SOAP web service. The Zend_Soap library provides various functions for creating a SOAP server and a SOAP client.
Creating a SOAP Server

1) Create a WSDL document 

The WSDL document defines the operations that the web service provides. A WSDL is an XML document in the Some of the elements of a WSDL document are:

Definitions – Root element of a WSDL document.

Types – data types used in web service. It can be simple or complex types.

Message – Defines the data being transmitted.

portType – Defines the set of operations.

Binding – Defines message format and protocol details for operations.

Port – Defines an endpoint by associating an address with a binding.

2) Write a class or method to serve the request

Create a Soap Server object using the WSDL file as argument.

$wsdl = ‘http://’ .$_SERVER[‘HTTP_HOST’] . ‘/services.wsdl’;

$server = new Zend_Soap_Server($wsdl);

Add the function to the Soap Server object using the  addFunction() method. Define the function1 with all the operations it could do.


Handle a SOAP request. The handle method prepares the Response XML based on output given by function1.

Creating a SOAP Client
Create a SOAP client using the Zend_Soap_Client class. The WSDL document, service.wsdl, is specified as an argument to the constructor. The WSDL document specifies the operations that are available to the SOAP client.

$client = new Zend_Soap_Client(“service.wsdl”);

$result1 = $client-> function1 ($args);

$args is an array from which Zend automatically prepares the Request XML.


WSDL can be generated automatically with Zend_Soap_AutoDiscover class. Autodiscovery generates the WSDL file and posts it to the browser.

$autodiscover = new Zend_Soap_AutoDiscover();



Next Post

Leave a Reply