Services_Webservice finally made it into PEAR. Phillipe Jausions and Matthew Fonda are now contributing to the project.
We already released the first alpha version and ask everyone to download and test it.
The package will/should do all the annoying stuff that comes to you when creating webservices, like:
- wsdl (webservice description language) creation
- disco (discovery) creation
- instantiating a php SoapServer
- infopage of the webservice
To see what the package does for you, have a quick look here.
If you are interested have a look at the examples I prepared.
1) Simple example creates wsdl, disco, infopage and soapserver.
include_once('Services/Webservice.php'); class myService extends Services_Webservice { /** * Says "Hello!" * * @param int * @return string */ public function hello($i ) { //create some logic here return 'myString'; } } $myService = new myService( 'myService', 'example webservice description', array('uri' => 'myService', 'encoding' => SOAP_ENCODED,'soap_version' => SOAP_1_2) ); $myService->handle();
2) A more advanced service with support for complex types
include_once('Services/Webservice.php'); class classB { /** * @var string */ public $c; public function __construct($c) { $this->c=$c; } } class myService extends Services_Webservice { /** * Says "Hello!" * * @param int * @param string * @return classB */ public function hello($i, $j ) { //create some logic here return new SoapVar(new ClassB('myString'), SOAP_ENC_OBJECT, 'classB', 'urn:myService'); } } $myService = new myService( 'myService', 'example webservice description', array('uri' => 'myService', 'encoding' => SOAP_ENCODED,'soap_version' => SOAP_1_2) ); $myService->handle();
3) Using arrays
include_once('Services/Webservice.php'); class myService extends Services_Webservice { /** * Says "Hello!" * * @param int[] * @return string[] */ public function hello($i) { $strArray = array(); $strArray[] = $i[0].'a'; $strArray[] = $i[1].'b'; $strArray[] = $i[2].'c'; $strArray[] = $i[3].'d'; $strArray[] = $i[4].'e'; return $strArray; } } $myService = new myService( 'myService', 'example webservice description', array('uri' => 'myService', 'encoding' => SOAP_ENCODED,'soap_version' => SOAP_1_2) ); $myService->handle();
4) Using arrays, complex types
include_once('Services/Webservice.php'); class classB { /** * @var int[] */ public $i; public function __construct() { $this->i = array(1,2,3,4,5); } } class myService extends Services_Webservice { /** * Says "Hello!" * * @return classB[] */ public function hello() { //create some business logic here $classB[] = new SoapVar(new ClassB(),SOAP_ENC_OBJECT,'classB','urn:myService'); return $classB; } } $myService = new myService( 'myService', 'example webservice description', array('uri' => 'myService', 'encoding' => SOAP_ENCODED,'soap_version' => SOAP_1_2) ); $myService->handle();
Please do not expect from the package to work properly yet. The wsdl-creating is quite stable.
While doing some extensive test with .net-clients I discovered the wsdl is also used for typemapping the
soap-messages. So the whole wsdl had to be recreated.
I am waiting for your feedback!
Manfred <crafics@php.net>
Schreibe einen Kommentar