SOAP(Simple Object Access Protocol ) is probably the most used web service protocol today. It relies on XML as its message format, and it uses HTTP for message transmission. The SOAP server uses WSDL(Web Services Description Language ) to describe its services to external clients. WSDL is simply an XML-based language that provides a model for describing Web services.
Back in the old days you had to know a lot about SOAP and WSDL create a web service. Have a look at http://www.php.net/soap to see what I mean. Definitely not very good looking. Luckily Zend Framework has a nice component, Zend_Soap, that handles all the SOAP hard work you would be supposed to do.
So without further ado, here's the code(discussing a Zend Framework component, the code presented here uses the Zend MVC, but you can use it without the Zend MVC):
This is the source code for the controller:
require_once realpath(APPLICATION_PATH .
'/../library/').'/Soaptest.php';
class SoapController extends Zend_Controller_Action
{
//change this to your WSDL URI!
private $_WSDL_URI="http://192.168.188.128:8081/soap?wsdl";
public function indexAction()
{
$this->_helper->viewRenderer->setNoRender();
if(isset($_GET['wsdl'])) {
//return the WSDL
$this->hadleWSDL();
} else {
//handle SOAP request
$this->handleSOAP();
}
}
private function hadleWSDL() {
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('Soaptest');
$autodiscover->handle();
}
private function handleSOAP() {
$soap = new Zend_Soap_Server($this->_WSDL_URI);
$soap->setClass('Soaptest');
$soap->handle();
}
public function clientAction() {
$client = new Zend_Soap_Client($this->_WSDL_URI);
$this->view->add_result = $client->math_add(11, 55);
$this->view->not_result = $client->logical_not(true);
$this->view->sort_result = $client->simple_sort(
array("d" => "lemon", "a" => "orange",
"b" => "banana", "c" => "apple"));
}
}
And the code for the Soaptest.php class:
class Soaptest {
/**
* Add method
*
* @param Int $param1
* @param Int $param2
* @return Int
*/
public function math_add($param1, $param2) {
return $param1+$param2;
}
/**
* Logical not method
*
* @param boolean $param1
* @return boolean
*/
public function logical_not($param1) {
return !$param1;
}
/**
* Simple array sort
*
* @param Array $array
* @return Array
*/
public function simple_sort($array) {
asort($array);
return $array;
}
}
You can also download the full project here.
As you can see you don't have to write a lot of code to back up the web service.
Let's discuss the controller first, because there's where the “magic†happens. The index action handles two types of requests: the request for the WSDL, handled by the hadleWSDL() method and the actual SOAP request, handled by the handleSOAP() method.
You can go ahead and try to see how your WSDL looks by accessing http://URL_TO_WEB_SERVICE/soap?wsdl , where URL_TO_WEB_SERVICE is the URL where you have deployed the example. Now imagine that you would have to construct and maintain this yourself, by hand, as old school bearded guys would. Well you don't, because this is handled by Zend_Soap_AutoDiscover which will create the WSDL file for you. The only thing that Zend_Soap_AutoDiscover needs to know is the class you want to use for the web service. Also, because PHP is not strongly typed, you will have to put PHPDoc blocks, because SOAP needs to know what types you are using as parameters and what types you are returning. Have a look here if PHPDoc does not ring a bell .
The SOAP server is handled by the Zend_Soap_Server class, and all it needs is the class you intend to use for the web service, and the URI to your WSDL file. Remember when you checked out how the WSDL file looks? That's exactly the URI you will have to use. In the example you will have to put that into the $_WSDL_URI variable, defined in the SoapController.
That was the SOAP server. Simple, right? Now let's have some tests on the server by implementing a simple SOAP client. The client is handled by the Zend_Soap_Client class that is constructed in the same manner as the server class, it needs just the URI to the WSDL file. After you have constructed the client, you can access the methods defined by the SOAP server in the same way you would access the methods of an object. In the example above you have a simple class, called Soaptest, that defines three very simple methods. Feel free to change the class and test your own methods. While you are playing with the server, you might notice that the WSDL file is cached, so if you change something into the Soaptest.php file, you might not get the expected result. Just delete the cached WSDL file from /tmp/wsdl-* while you do your tests.
Source - http://bogdan-albei.blogspot.com/2009/05/quickstart-web-services-with-soap-and.html

written by Dawe, October 20, 2010
Use:
if( $this->getRequest()->getParam('wsdl') ) {
...
}
written by Dawe, October 20, 2010
Use:
if( $this->getRequest()->getParam('wsdl') ) {
...
}
written by Dawe, October 20, 2010
Use:
if( $this->getRequest()->getParam('wsdl') ) {
...
}
written by Dawe, October 20, 2010
Use:
if( !is_null($this->getRequest()->getParam('wsdl')) ) {
...
}
written by ....., March 24, 2011
Thats clean, when you use the default state from getParam
written by adesh kumar, July 26, 2011
you can use like this above condition
if(array_key_exists('wsdl', $this->getRequest()->getParams()))
{
}
written by AlexanderPlutov, September 23, 2011
written by zend webservice newbie, September 29, 2011
I am new to webservice. I copied the code and changed the wsdl url
I am not able to run the client action.
I am getting an error stating :
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://10.76.233.199:8083/soap?wsdl'
I executed the stated wsdl url in browser and it is working properly i.e. giving xml correctly.
I am not able to figure out the issue.
Any help would be gr8
Thanks
written by Shanmuganathan, October 11, 2011
written by Shanmuganathan, October 11, 2011
written by Shanmuganathan, October 11, 2011

- 08/02/2012 04:36 - Virtualization With Xen On CentOS 6.2 (x86_64)
- 08/02/2012 04:34 - Virtual Users/Domains With Postfix/Courier/MySQL/SquirrelMail (CentOS 6.2 x86_64)
- 08/02/2012 04:29 - Running ownCloud3 On Nginx (LEMP) On Debian Squeeze/Ubuntu 11.10
- 23/01/2012 04:38 - The Perfect Server - CentOS 6.2 x86_64 With nginx [ISPConfig 3]
- 20/01/2012 04:05 - Securing Your ISPConfig 3 Installation With A Free Class1 SSL Certificate From StartSSL
- 11/08/2010 04:59 - Installing Nginx With PHP5 And MySQL Support On OpenSUSE 11.3
- 21/07/2009 09:01 - Zend Framework 1.9.0 Preview Release Now Available
- 09/07/2009 02:14 - Zend Framework 1.8.4pl1 Now Available
- 01/07/2009 10:41 - Zend Studio 7.0 Beta is Available
- 28/05/2009 14:12 - Zend Server 4.0.2 updates PHP middleware for Macs
- 21/05/2009 02:59 - Zend plugs PHP into Amazon cloud
- 14/05/2009 07:44 - Zend Framework 1.8.1 Released
- 04/05/2009 07:48 - Zend Framework 1.8.0 Released
- 24/04/2009 04:23 - Zend Server Released !
- 13/04/2009 15:48 - Zend Framework 1.8 PREVIEW Release


