Your Ad Here

WorldofPHP.NET >> PHP XML

Web Services Implementation using PHP and SOAP

Basic Introduction on PHP , Web Services and SOAP

Published Date : 07 Dec 2007

Author : hand
PHP Version : PHP 5
Platform : Linux,Windows
 
Views : 2093
Rating : (0 votes so far)
Email to a Friend | Print this Article | Add to Favourites | Report Error

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).

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:

  • It is a framework for describing what is in a message and how to process the message
  • It is a set of Encoding rules
  • 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:

include('nusoap.php');

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.

Simple PHP SOAP Client Example

Below is the sample code for the client which sends the request to the remote server for validating the string, which is passed as a parameter to the server.

<? php require('nusoap.php'); $string = 'HelloWorld'; $stringArray = array($string); $s = new soapclient('http://localhost/validatestring.php'); $result = $s->call('validatestring','$stringArray'); if(!$error = $s->getError()) { echo 'String :' . $result; } else { echo '$Error :' . $error; } ?>


      Other Related and Popular Articles :

      Understanding Sessions Object in PHP
      Basic Introduction on using Session objects in PHP
      PHP security tips for upload files
      Always restrict the file types that you allow and don’t rely on a blacklist approach.
      Developing a Login System with PHP and MySQL
      Developing a Login System with PHP and MySQL
      PHP Form Mailer
      How to create PHP Form Mailer to stop spammer

      Author Profile : hand

      Click here to view Author Profile


      How would you rate the quality of this content?
      Poor Excellent

      Comments

      Leave New Comments


      Article Content copyright by hand
      Everything else Copyright © by WorldofPHP.NET 2008