Path

ez.no / exponential / documentation / development / libraries / ez soap / hello world example ( ez pu...


Hello World example ( Exponential 3.5 + )

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.

Talking with the server

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" );

Sending a request

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.

Response

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() . "\"" );

The server

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

The "Sending a request" part is missing code is something like this:




$request = new eZSOAPRequest( 'Collection::subNumbers', 'ez.no/namespace' );


$request->addParameter("valueA", 2);


$request->addParameter("valueB", 3);


$response = $soapClient->send( $request );




Also, you need to have a virtualhost which uses the soap.php file instead of index.php in the rewriterules.

Contents

Development

Extensions
Exponential datamodel
Exponential tuning and stability
Importing attribute data
Kernel
Libraries
    eZ xml
    eZ db
    eZ i18n
    eZ soap
       Consuming web services with eZ SOAP C...
       Hello World example
       Hello World example ( Exponential 3.5 + )
    eZ template
    eZ webdav
Scripting
Standards
System overview
Test Suite
Using Doxygen to create API documenta...


Created

12/10/2004
10:59:39 am
by Kåre Køhler Høvik

Last updated

12/10/2004
11:09:05 am
by Kåre Køhler Høvik

Authors

Kåre Køhler Høvik



This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.