Home arrow PHP arrow Page 4 - Developing SOAP Clients using PHP

PHP's SOAP Extension - PHP

SOAP (Simple Object Access Protocol) provides a flexible communication layer between applications, regardless of platform and location. As long as both the server and the client speak SOAP, they can communicate. A PHP-based web application can ask a Java database application to get some information. In this article we will try to focus on different methods of developing SOAP web service clients in PHP.

TABLE OF CONTENTS:
  1. Developing SOAP Clients using PHP
  2. Debugging NuSOAP
  3. PEAR::SOAP
  4. PHP's SOAP Extension
By: Mamun Zaman
Rating: starstarstarstarstar / 10
August 14, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

From PHP version 5.0.4, PHP has a SOAP extension. Using this SOAP Extension supports SOAP client applications with a class called SoapClient, which offers the following main functions:

  • SoapClient->__construct() - Constructs a new SoapClient object.
  • SoapClient->__soapCall() - Calls a SOAP function.
  • SoapClient->__getFunctions() - Returns a list of SOAP functions.
  • SoapClient->__getLastRequestHeaders() - Returns the last SOAP request headers.
  • SoapClient->__getLastRequest() - Returns the last SOAP request.
  • SoapClient->__getLastResponseHeaders() - Returns the last SOAP response headers.
  • SoapClient->__getLastResponse() - Returns the last SOAP response.

The SoapClient->__construct() constructor creates SoapClient objects in WSDL or non-WSDL mode. This function also has some options like the location and uri options, where location is the URL to request and uri is the target namespace of the SOAP service.

SoapClient->__getFunctions() allows you to get a list of functions supported by the target node. This function is only valid in WSDL mode. After getting the supported functions, SoapClient->__soapCall() allows you to make an RPC function call on the target SOAP node. Our above client implementation can also be developed using the PHP SOAP extension as shown below.

<?php
//Create the SoapClient object
$client = new SoapClient("http://localhost/add.wsdl");

//Call the add function of SOAP server
echo $client->__soapCall("add", array(5, 7));

?>

If we are using WSDL then we can simply call the remote function as local function. The above example will generate same output as below.

<?php
//Create the SoapClient object
$client = new SoapClient("http://localhost/add.wsdl");

//Call the add function of SOAP server (possible only in WSDL Mode)
echo $client->add(5, 7);

?>

The PHP SOAP extension is very useful for creating SOAP headers with security credentials. Usernames and passwords can be securely encrypted and then added into SOAP headers using the SOAP extension of PHP.

In this article I tried to focus on some different implementations of SOAP using PHP. Both PEAR::SOAP and NuSOAP are easy to install and use. But I personally like PHP5's SOAP extension, because it has more features than the other two. But if you are using a PHP version earlier than 5.0.4, you have to use these libraries.



 
 
>>> More PHP Articles          >>> More By Mamun Zaman
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: