PHP Doku:: The SoapServer class - class.soapserver.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzWeb ServicesSOAPThe SoapServer class

Ein Service von Reinhard Neidl - Webprogrammierung.

SOAP

<<SoapClient::SoapClient

SoapServer->addFunction()>>


UnterSeiten:

The SoapServer class

Einführung

The SoapServer class provides a server for the » SOAP 1.1 and » SOAP 1.2 protocols. It can be used with or without a WSDL service description.

Klassenbeschreibung

SoapServer {
/* Methoden */
void SoapServer::addFunction ( mixed $functions )
public void SoapServer::addSoapHeader ( SoapHeader $object )
public void SoapServer::fault ( string $code , string $string [, string $actor [, string $details [, string $name ]]] )
array getFunctions ( void )
void handle ([ string $soap_request ] )
void setClass ( string $class_name [, mixed $args [, mixed $... ]] )
public void SoapServer::setObject ( string $object )
void setPersistence ( int $mode )
SoapServer::SoapServer ( mixed $wsdl [, array $options ] )
}

Inhaltsverzeichnis


4 BenutzerBeiträge:
- Beiträge aktualisieren...
mikkel at nsales dot dk
3.06.2010 0:15
If you want to return a custom object array from a nusoap webservice, you have to cast the objects to arrays like so:

<?php
$users
= array();
while(
$res = $db_obj->fetch_row())
{
 
$user = new user();
 
$user->Id = $res['id'];
 
$user->Username = $res['username'];
 
$user->Email = $res['email'];
 
 
$users[] = (array) $user;
}

return (
$users);
?>
junk2cm at gmx dot de
25.05.2010 9:54
As the SoapServer class lacks the possibility of dealing with SOAP-Headers, my following workaround is suitable to my needs when I had to do authentication via the SOAP-Headers:
1. Use a class which handles SOAP requests and let the constructor of this class take the sent headers.
2. Before invoking the SoapServer extract the SOAP-Header from the incoming raw data.
3. When using setClass pass the extracted header to the handling class.

In Your Server-Skript do things like this
<?php
$hdr
= file_get_contents("php://input");
if (
strpos($hdr,'<s:Header>')===false) {
   
$hdr = null;
} else {
   
$hdr = explode('<s:Header>',$hdr);
   
$hdr = explode('</s:Header>',$hdr[1]);
   
$hdr = $hdr[0];
}
$srv = new SoapServer('Your_wsdl');
$srv->setClass("ServiceClass",$hdr);
$srv->handle();
?>

And the service class is like this:
<?php
class ServiceClass {
    var
$IsAuthenticated;

    function
__construct($hdr) {
       
$this->IsAuthenticated = false;
        if (
$hdr!=null) {
           
$this->header = simplexml_load_string($hdr);
           
//Your authentication stuff goes here...
       
}
    }
   
    function
SomeFunctionOfTheService($a) {
        if (
$this->IsAuthenticated) {
           
//here Your function...
       
}
    }

}
?>
carlos dot vini at gmail dot com
20.05.2010 22:55
SoapServer does not support WSDL with literal/document. I have a class:

<?php
class My_Soap {
   
/**
     * Returns Hello World.
     *
     * @param string $world
     * @return string
     */
   
public function getInterAdmins($world) {
        return
'hello' . $world;
    }
}
?>

To fix this I had to create proxy class:
<?php
class My_Soap_LiteralDocumentProxy {
   public function
__call($methodName, $args) {
      
$soapClass = new My_Soap();
      
$result = call_user_func_array(array($soapClass, $methodName),  $args[0]);
       return array(
$methodName . 'Result' => $result);
   }
}
?>

Now make sure that the WSDL is created using My_Soap. And that the Server is created using My_Soap_LiteralDocumentProxy:

<?php

if (isset($_GET['wsdl'])) {
   
$wsdl = new Zend_Soap_AutoDiscover(); // It generates the WSDL
   
$wsdl->setOperationBodyStyle(array(
       
'use' => 'literal'
   
));
   
$wsdl->setBindingStyle(array(
       
'style' => 'document'
   
));
   
$wsdl->setClass('My_Soap');
   
$wsdl->handle();
} else {
   
$server = new Zend_Soap_Server('http://localhost/something/webservice.php?wsdl');
   
$server->setClass('My_Soap_LiteralDocumentProxy');
   
$server->handle();
}

?>
dsubar at interna dot com
26.12.2009 6:49
Do not put a SoapServer and a SoapClient in the same PHP file. This seems to cause arbitrary behavior. On the PHP interpreter in Eclipse, everything worked fine. Under MAMP, I got an undocumented error. In moving the client from the same file as the server, everything worked fine.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)