ZCE 5.3



	// defined by WSDL (pronounced wishdl)
	// new SoapClient($wsdl) / (NULL, array(location, uri))
	// arguments (encoding)
	// debugging: getLastRequestHeader()
	// server: new SoapServer($wsdl) / handle()
	// class: setClass / autodiscovery Zend (doc /**)
	// __getFunctions / doRequest / getLastResponseHeders / setCookie

* Web Services Basics (214)

Web services are noted for being extensible and interoperable, and they are characterized by their use of 
XML to communicate between and among disparate systems.

There are three popular types of Web Services in use today: XMLRPC, SOAP, and REST. PHP 5 contains 
tools particularly suited for SOAP and RESTWeb services.

* SOAP Basics

SOAP is a powerful tool for communication between disparate systems, as it allows the definition and 
exchange of complex data types in both the request and response, as well as providing a mechanism for 
various messaging patterns, the most common of which is the Remote Procedure Call (RPC).

SOAP is intrinsically tied to XML because all messages sent to and from a SOAP server are sent in a 
SOAP envelope that is an XML wrapper for data read and generated by the SOAP server.

PHP 5 makes the creation of both servers and clients very easy.

A SOAP Web service is defined by using a Web Service Description Language (WSDL, pronounced 
"whisdl") document. This, in turn, is yet another XML document that describes the function calls made 
available by a Web service, as well as any specialized data types needed by it.

* Accessing SOAP-based Web Services (Client)

The SoapClient class provides what is essentially a one-stop solution to creating a SOAP client - all you 
really need to do is provide it with the path to a WSDL file, and it will automatically build a PHP-friendly 
interface that you can call directly from your scripts.

First, you need to activate extension in /apache/bin/php.ini ( ;extension=php_soap.dll )

	// World Championship football 2010(South Africa)
	$client = new SoapClient("");' target='_blank'>");' target='_blank'>");' target='_blank'>");
	try {
		$topScorers = $client->TopGoalScorers(array('iTopN'=>5));
			// var_dump($topScorers);
		if (count($topScorers->TopGoalScorersResult->tTopGoalScorer)) {
			foreach($topScorers->TopGoalScorersResult->tTopGoalScorer as $k=>$v) {
				echo "<br>{$v->sName}: {$v->iGoals} goals";
				/* Output:
				Alan Dzagoev: 3 goals
				Cristiano Ronaldo: 3 goals
				Fernando Torres: 3 goals
				Mario Balotelli: 3 goals
				Mario Gómez: 3 goals
	} catch (SoapFault $e) {
		echo $e->getMessage;

* Arguments

The constructor of the SOAPClient class also accepts, as an optional second parameter, an array of options 
that can alter its behaviour; for example, you can change the way data is encoded, or whether the entire 
SOAP exchange is to be compressed, and so on.

	$client = new SoapClient("", ' target='_blank'>", array(' target='_blank'>", ' target='_blank'>", array(
			// Mario Gomez: 3 goals

* No WSDL file

The WSDL is supposed to be a public document that describes the SOAP service, so describes the 
signatures of all the methods available in the service.

There may be service providers who want to expose a service to certain consumers, but who don't want to 
make the signature of the service public.

If you are accessing a SOAP service that does not have a WSDL file, it is possible to create a SOAP client 
in non-WSDL mode by passing a NULL value to the SoapClient constructor instead of the location of the 
WSDL file. In this case, you will have to pass the URI to theWeb service's entry point as part of the second 

	$client = new SoapClient(NULL, array(
		'location' => '',' target='_blank'>',
		'uri' => '',' target='_blank'>',

			A sample Time service
			The following operations are supported.

	$return = $client->__soapCall("getTimeZoneTime",
		array(new SoapParam('CET', 'ns1:timezone')),
		array('soapaction' => '')' target='_blank'>')
		// Central European Time	Europe	UTC + 2 hours
		// Output: string(8) "11:42 AM"

* Debugging

SoapClient provides special methods thatmake it possible to debug messages sent to and received from a 
SOAP server. They can be turned on by setting the trace option to 1 when instantiating a SOAP client 
object. This, in turn, will make it possible for you to access the raw SOAP headers and envelope bodies.

		$client = new SoapClient(NULL, array(
			'location' => '',' target='_blank'>',
			'uri' => '',' target='_blank'>',
			'trace' => 1,
		$return = $client->__soapCall("getTimeZoneTime",
			array(new SoapParam('CET', 'ns1:timezone')),
			array('soapaction' => '')' target='_blank'>')

		echo $client->__getLastRequestHeaders();

			/* Outputs

				POST /TimeService/TimeService.asmx HTTP/1.1
				Connection: Keep-Alive
				User-Agent: PHP-SOAP/5.3.16
				Content-Type: text/xml; charset=utf-8
				SOAPAction: ""
				Content-Length: 540

		echo $client->__getLastRequest();

			/* Outputs
				< xml version="1.0" encoding="UTF-8" >
							<ns1:timezone xsi:type="xsd:string">CET</ns1:timezone>


* Creating SOAP-based Web Services (Server)

Just as SoapClient, simplifies the task of building aWeb service client, the SoapServer class performs all of 
the background work of handling SOAP requests and responses. When creating a SOAP server, you simply 
startwith a class that contains the methods you wish tomake available to the public through a Web Service 
and use it as the basis for a SoapServer instance.

When creating a SOAP server with SoapServer, you must decide whether your server will operate in WSDL 
or non-WSDL mode. At present, SoapServer will not automatically generate a WSDL file based on an 
existing PHP class, although this feature is planned for a future release. For now, you can either create your
WSDL files manually - usually an incredibly tedious task, use a tool (like the Zend Studio IDE) that will
generate one for you, or choose not to provide one at all. For the sake of simplicity, our example SOAP 
server will operate in non-WSDL mode.

		// http://localhost/tests/webservices/server.php (Server)

		class MySoapServer 
			public function getMessage() 
				return "Hello World";
		$server = new SoapServer(NULL, array('uri' => 'http://localhost/tests/webservices/'));

			// Once we have created the server,
			// we need to inform it of the class that we want the web service to be based on.

			// Finally, to process incoming requests, call the handle() method:

		// http://localhost/tests/webservices/index.php (Client)

		$client = new SoapClient(NULL, array(
			'location' => 'http://localhost/tests/webservices/server.php',
			'uri' => 'http://localhost/tests/webservices/',
		echo $client->getMessage();
			// Outputs: Hello World

* SoapClient Methods

	* __getFunctions() - only works in WSDL mode

			// World Championship football 2010(South Africa)
		$client = new SoapClient("");' target='_blank'>");' target='_blank'>");' target='_blank'>");
		$functions = $client->__getFunctions();
			/* Outputs
			array(42) {
			   string(65) "AllPlayerNamesResponse AllPlayerNames(AllPlayerNames $parameters)"

	* __doRequest()

		class MySoapClient extends SoapClient {

			function __construct($wsdl, $options = array()) {
			  parent::__construct($wsdl, $options);
			// This method can be overridden in subclasses to implement different transport layers, 
			// perform additional XML processing or other purpose. 
			function __doRequest($request, $location, $action, $version) {
				return parent::__doRequest($request, $location, $action, $version);
		$client = new MySoapClient("");' target='_blank'>");' target='_blank'>");' target='_blank'>");
		$topScorers = $client->TopGoalScorers(array('iTopN'=>5));

	* __getLastResponseHeaders() - only works with trace = 1

			$client = new SoapClient("", ' target='_blank'>", 

				var_dump($client->__getLastResponseHeaders ());
				/* Outputs:
					HTTP/1.1 200 OK
					Cache-Control: private, max-age=0
					Content-Length: 2094
					Content-Type: text/xml; charset=utf-8
					Server: Microsoft-IIS/7.5
					Web-Service: Visual DataFlex 16.1
					Date: Fri, 02 Nov 2012 12:46:39 GMT

	* __setCookie()

			$client = new SoapClient("",

			$client->__setCookie("myname", "catalin" );
				/* Outputs:
					Cookie: myname=catalin;

Testare !!

$client = new SoapClient("", array(

                                                'proxy_host'     => "isabrd", //"",

                                                'proxy_port'     => 8080,

                                                'proxy_login' => "BRDcatalin.prescure",

                                                'proxy_password' => "XXX",


$auth = array('Code'=>'4a182071-8dc9-4127-a972-acdf84ba79d1');

$result= $client->call('register', $auth);