PHP Doku:: Behandeln von SOAP-Anfragen - soapserver.handle.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzWeb ServicesSOAPThe SoapServer classSoapServer->handle()

Ein Service von Reinhard Neidl - Webprogrammierung.

The SoapServer class

<<SoapServer->getFunctions()

SoapServer->setClass()>>

SoapServer->handle()

(PHP 5 >= 5.0.1)

SoapServer->handle() Behandeln von SOAP-Anfragen

Beschreibung

void SoapServer::handle ([ string $soap_request ] )

Verarbeiten einer SOAP-Anfrage, ruft benötigte Funktionen auf und schickt eine Antwort zurück.

Parameter-Liste

soap_request

SOAP-Anfrage. Wenn das Argument nicht gegeben ist, wird die Anfrage aus der PHP-Variablen $HTTP_RAW_POST_DATA verarbeitet.

Rückgabewerte

Es wird kein Wert zurückgegeben.

Beispiele

Beispiel #1 Beispiele

<?php
function test($x)
{
    return 
$x;
}

$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>


4 BenutzerBeiträge:
- Beiträge aktualisieren...
Artur Graniszewski
15.11.2009 19:19
Be aware that SoapServer::handle(); method sends additional HTTP headers to the browser. One of them is "Content-Type: application/soap+xml". If you want to execute SOAP methods locally as a part of SoapClient::__doRequest() (see example at http://pl2.php.net/manual/en/soapclient.dorequest.php ) you may need to reset (override) this header back to "Content-Type: text/html" like so:

<?php
function Add($x,$y) {
  return
$x+$y;
}

class
LocalSoapClient extends SoapClient {

  function
__construct($wsdl, $options) {
   
parent::__construct($wsdl, $options);
   
$this->server = new SoapServer($wsdl, $options);
   
$this->server->addFunction('Add');
  }

  function
__doRequest($request, $location, $action, $version) {
   
ob_start();
   
$this->server->handle($request);
   
$response = ob_get_contents();
   
ob_end_clean();
    return
$response;
  }

}

$x = new LocalSoapClient(NULL,array('location'=>'test://',
                                  
'uri'=>'http://testuri.org'));

header("Content-Type: text/html");

var_dump($x->Add(3,4));

?>
tom at backslashinteractive dot com
3.10.2008 19:54
In response to Blizzke:

Sometimes this problem can be hidden by an Apache segmentation fault along with an HTTP headers error SoapFault thrown to the client.

If you get either of those 2, try checking to make sure that style="rpc" in your WSDL file's soap:operation's.

-T
Blizzke at gmail dot com
12.03.2008 13:39
Seems pretty logical once you find the solution, but it took me quite a while to figure this one out:
If you are using WSDL based SOAP requests and you have more than one operation in your binding (with the same parameters), make sure the <soap:operation> style is set to rpc, NOT body!

When you specify 'body' here, all that will be transmitted in the request is the parameters for the function call, and SoapServer->handle() will use the first function it finds with the same parameter-makeup to handle the call.

ie If you have 2 functions:
<?php
function One ( string $blah );
function
Two ( string $blah );
?>
Making a client call with SoapClient -> Two ( 'test' ); will result in One ( ) being called when your 'type' is set to 'body'

The actual method to call will only be included in the request when your type is set to 'rpc', resulting in the expected behavior
king dot maxemilian at noos dot fr
21.08.2007 18:23
Sometime, it happens that PHP does not detect anything in $HTTP_RAW_POST_DATA.

To solve this problem and make it work in any case:

function soaputils_autoFindSoapRequest()    {
    global $HTTP_RAW_POST_DATA;
   
    if($HTTP_RAW_POST_DATA)
        return $HTTP_RAW_POST_DATA;
   
    $f = file("php://input");
    return implode(" ", $f);
}

$server = new SoapServer($wsdl);
$server->setClass($MyClass);

$server->handle(soaputils_autoFindSoapRequest());



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",...)