ez.no / exponential / documentation / development / libraries / ez soap / hello world example ( ez pu...
Every SDK with programming examples must contain a hello world example, eZ soap is no exception. This example shows how you can send a request to a SOAP server and print out the result.
he default transport in eZ soap is HTTP. In this example we set up a client object to talk to the server myserver.com and the path /helloworld.
include_once( "lib/ezsoap/classes/ezsoapclient.php" ); include_once( "lib/ezsoap/classes/ezsoaprequest.php" ); $client = new eZSOAPClient( "myserver.com", "/helloworld" );
You need to prepare a request object to send. In this example we have a simple request without any parameters. All we need to do is to give the request name, helloWorld, and the target namespace, http://ez.no/sdk/soap/examples. This object is then sent to the server via the client.
When the request is sent you will get a response returned from the server. This response will be returned by eZ soap as a eZSOAPResponse object. If the server returned a fault the faultcode and faultstring is printed. If all was successful the response value from the server is printed.
As you can see the values returned from the server is automatically converted to PHP types, all the encoding/decoding of data is handled by the eZ soap library.
if ( $response->isFault() ) { print( "SOAP fault: " . $response->faultCode(). " - " . $response->faultString() . "" ); } else print( "Returned SOAP value was: \"" . $response->value() . "\"" );
To create a SOAP server is just as simple as the client. Specify you SOAP extension in the override for settings/soap.ini.
[ExtensionSettings] SOAPExtentensions[]=my_soap_extension
Then you need to register the functions which should be available. This must be done in extensions/my_soap_extension/soap/initialize.php. Soap handles the rest. The $server object is provided by the framework, and must be used to register SOAP functions.
// in extensions/my_soap_extension/soap/initialize.php $server->registerFunction( "helloWorld" ); function helloWorld() { return "Hello World!"; }
The SOAP service is now available accessing soap.php as the URL. Multiple SOAP extensions can be used.
Comments
Response
Kristian Hole
Thursday 22 December 2005 2:20:52 pm
Also, you need to have a virtualhost which uses the soap.php file instead of index.php in the rewriterules.