Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : SOAP Functions : SoapServer->addFunction()

SoapServer->addFunction()

Adds one or several functions those will handle SOAP requests ()

SoapServer {
  void addFunction(mixed functions);
}

Exports one or more functions for remote clients.

Parameters

functions

To export one function, pass the function name into this parameter as a string.

To export several functions, pass an array of function names.

To export all the functions, pass a special constant SOAP_FUNCTIONS_ALL.

Note:

functions must receive all input arguments in the same order as defined in the WSDL file (They should not receive any output parameters as arguments) and return one or more values. To return several values they must return an array with named output parameters.

Return Values

No value is returned.

Examples

Example 2282. Some examples

<?php

function echoString($inputString)
{
   return
$inputString;
}

$server->addFunction("echoString");

function
echoTwoStrings($inputString1, $inputString2)
{
   return array(
"outputString1" => $inputString1,
               
"outputString2" => $inputString2);
}
$server->addFunction(array("echoString", "echoTwoStrings"));

$server->addFunction(SOAP_FUNCTIONS_ALL);

?>


Code Examples / Notes » soap_soapserver_addphp

nathan o'sullivan

You may be left wondering, as I was, how to return a complex type - consider the following WSDL snippets, for a method called Login:
<xs:element name="Login">
       <xs:complexType>
         <xs:sequence>
           <xs:element minOccurs="0" maxOccurs="1" name="username" type="xs:string" />
           <xs:element minOccurs="0" maxOccurs="1" name="password" type="xs:string" />
         </xs:sequence>
       </xs:complexType>
     </xs:element>
  <xs:complexType name="UserInfo">
       <xs:sequence>
         <xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:string" />
         <xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
         <xs:element minOccurs="0" maxOccurs="1" name="Nickname" type="xs:string" />
         <xs:element minOccurs="0" maxOccurs="1" name="Email" type="xs:string" />
       </xs:sequence>
     </xs:complexType>
  <xs:element name="LoginResponse">
       <xs:complexType>
         <xs:sequence>
           <xs:element minOccurs="0" maxOccurs="1" name="LoginResult" type="s0:UserInfo" />
         </xs:sequence>
       </xs:complexType>
     </xs:element>
Here's a working Login function  that I've added with add SoapServer::addFunction
function Login($username, $password)
{
 return array("LoginResult", array("Id"=>1, "Name"=>"Nathan", "Nickname"=>"Nathan", "Email"=>"email address") );
}
The UserInfo complextype is represented by the inner array.  The outer array has just one element, "LoginResult".  The LogineResponse element  seems to be treated as a one-member array by PHP.


evan borgstrom

In response to comment by Nathan O'Sullivan about returning (or passing) a complex type, you can also use the stdClass() object.
Assume you define a complex type like so:
<xsd:complexType name="TestType">
       <xsd:all>
               <xsd:element name="A" type="xsd:string" />
               <xsd:element name="B" type="xsd:int" />
               <xsd:element name="C" type="xsd:boolean" />
       </xsd:all>
</xsd:complexType>
To use an object in place of an array you can do:
$test = new stdClass();
$test->A = "test string";
$test->B = 45;
$test->C = false;
$result = $client->Test($test);


16-jun-2005 01:10

function Login($username, $password)
{
 return array("LoginResult" => array("Id"=>1, "Name"=>"Nathan", "Nickname"=>"Nathan", "Email"=>"email address") );
}
Ok, Only a litte error in the last note.. :
"LoginResult" => array    and NOT      "LoginResult" , array


dotpointer

Be careful with SOAP_FUNCTIONS_ALL, as it adds ALL availiable PHP functions to your server.
This can be a potential security threat, imagine clients doing this:
echo $client->file_get_contents("c:\\my files\\my_passwords.doc");
And voila, they have the contents of your file my_passwords.doc.


Change Language


Follow Navioo On Twitter
is_soap_fault
SoapClient->__call()
SoapClient->__construct()
SoapClient->__doRequest()
SoapClient->__getFunctions()
SoapClient->__getLastRequest()
SoapClient->__getLastRequestHeaders()
SoapClient->__getLastResponse()
SoapClient->__getLastResponseHeaders()
SoapClient->__getTypes()
SoapClient->__setCookie()
SoapClient->__soapCall()
SoapFault->__construct()
SoapHeader->__construct()
SoapParam->__construct()
SoapServer->addFunction()
SoapServer->__construct()
SoapServer->fault()
SoapServer->getFunctions()
SoapServer->handle()
SoapServer->setClass()
SoapServer->setPersistence()
SoapVar->__construct()
use_soap_error_handler
eXTReMe Tracker