#native_company# #native_desc#
#native_cta#

Web Services Implementation using PHP and SOAP

By Rajeev Ranjan Rakesh
on November 14, 2008

Introduction to Web Services

Web Services is a system which enables and supports interoperability. It enables applications written in different languages, located in different places, running on different operating systems, to talk to each other, exchange information and perform different operations. The building blocks of Web Services are a
set of XML based standards namely SOAP (Simple Object Access Protocol), WSDL
(Web Services Description Language) and UDDI (Universal Description, Discovery,
and Integration).

The above diagram is the simplest diagram which can help you visualize web
services, and shows how two remote applications can interact with each
other using web services. The protocol used for this remote interaction is SOAP.

Simple Object Access Protocol (SOAP)

SOAP is a lightweight protocol for the exchange of information in a distributed environment. It is an XML-based protocol. The most important aspect of SOAP is its simplicity and extensibility. A SOAP message contains data in the form of XML. SOAP consists of three parts:

  1. It is a framework for describing what is in a message and how to process the message
  2. It is a set of Encoding rules
  3. It is a convention for representing remote procedure calls (request and response)

PHP and web Services

PHP is a widely used general purpose scripting language. It is basically a procedural
language, but it has the capabilities of an object oriented language also. Its syntax
is similar to Perl, C, Java, etc. It can be very easily embedded in the HTML which
makes web developement using PHP very easy. Some of the features of PHP which enhanced its capability for Web services development are discussed below.
Object Oriented Programming Capabilities
  • PHP supports XML
  • The CURL Extension of PHP (Client URL Library) allows us to communicate via different protocols such as HTTP, HTTPS, FTP, Telnet, LDAP).
  • The most important feature of PHP is it enables the open source web services implementation.

PHP Web Services using NuSoap

NuSoap is a group of PHP classes that allow us to send and receive SOAP messages over HTTP. You can download this nusoap.php library from http://www.nusphere.com. It is open source, licensed under the GNU LGPL. Once you have downloaded nusoap.php, you simply need to place it anywhere you like on your machine, but don??t forget to include the path of this file while including this file in your php code. I will suggest that you to keep it in the same work folder in which your code is located. To include NuSoap classes in our code:

If the path of the nusoap.php file (which can be absolute or relative) is incorrect, the above-mentioned code will generate a warning but will continue the processing of??the rest of the code. We can also use below-mentioned function as required.

  • require() :-it is similar to the include function but it will make the program halt in case of failure.
  • require_once() :- it is similar to require(), it won??t include the file if it has already been included.
  • include_once() :- similar to include(), it wont include if the file is already included.