|
|
SoapServer->__construct() (no version information, might be only in CVS) SoapServer->__construct() --
SoapServer constructor
Описаниеclass SoapServer { __construct ( mixed wsdl [, array options] ) }
This constructor allows the creation of SoapServer
objects in WSDL or non-WSDL mode.
Список параметров
wsdl
If you want the WSDL mode, you must set this to the URI of a WSDL file.
In the other case, you must set this to NULL and set the uri
option.
options
Allow setting a default SOAP version (soap_version),
internal character encoding (encoding),
and actor URI (actor).
The classmap option can be used to map some WSDL
types to PHP classes. This option must be an array with WSDL types
as keys and names of PHP classes as values.
Примеры
Пример 1. Some examples |
<?php
$server = new SoapServer("some.wsdl");
$server = new SoapServer("some.wsdl", array('soap_version' => SOAP_1_2));
$server = new SoapServer("some.wsdl", array('actor' => "http://example.org/ts-tests/C"));
$server = new SoapServer("some.wsdl", array('encoding'=>'ISO-8859-1'));
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
class MyBook {
public $title;
public $author;
}
$server = new SoapServer("books.wsdl", array('classmap' => array('book' => "MyBook")));
?>
|
|
add a note
User Contributed Notes
SoapServer->__construct()
php dot net at juamei dot com
31-Oct-2007 04:42
In response to Timo, it is possible to access Soap Headers from the SoapServer class and call methods to handle them. Rather than treat them seperately, they are treated as part of the Soap request.
To pass approximately wss standard headers (note that I couldn't get attributes from the header tags without text preprocessing, so standards compliance failed me), first create the following class on the client:
<?php
class SoapHeaderUsernameToken
{
public $Password;
public $Username;
public function __construct($l, $p)
{
$this->Password = $p;
$this->Username = $l;
}
}
?>
Now, set the Soap Headers:
<?php
$wsu = 'http://schemas.xmlsoap.org/ws/2002/07/utility';
$usernameToken = new SoapHeaderUsernameToken($this->username, $this->password);
$soapHeaders[] = new SoapHeader($wsu, 'UsernameToken', $usernameToken);
?>
Next instantiate the client object, add the headers and make the call:
<?php
$client = new SoapClient( $wsdl);
$client->__setSoapHeaders( $soapHeaders );
$client->__soapCall( $method, $params );
?>
Moving to the Server, you'll handle the Soap call somewhat like:
<?php
$server = new SoapServer( 'mysoapwsdl.wsdl' );
$server->setClass( 'mysoapclass' );
$server->handle();
?>
The key here is that the headers will be handled first by the server which will call the method mysoapclass::UsernameToken. The way we work this is the UsernameToken method authenticates the username / password combo and sets a protected class var. Then when the Soap Body is handled and the appropriate class method called, a check is made at the start of callable method to ensure authentication has been passed.
If the Soap auth header is missing, the soap body method will be called anyway so the check is essential in case a malevolent client deliberately leaves the headers off.
An example server class is below (missing various methods which I leave as an exercise to the reader to provide):
<?php
class mysoapclass {
public function UsernameToken( $username, $password ){
$this->Username = $username;
$auth = new $this->AuthClass( $username, $password, get_class($this) );
if( $auth->IsValid() ){
$this->Authenticated = true;
} else {
$this->ThrowSoapFault( 'auth' );
}
}
public function felineResponse( $action ){
if(!$this->Authenticated){
$this->ThrowSoapFault( 'auth' );
}
if( $action == 'stroke' ){
return 'purr';
} elseif( $action == 'tease' ){
return 'hiss';
}
}
}
?>
This is a adaptation of stuff I found online somewhere...
joel dot pearson at gmail dot com
10-Jul-2007 10:12
In response to jas [at] dansupport (dot) dk:
All you need to do is disable wsdl caching like so:
ini_set("soap.wsdl_cache_enabled", "0");
Then you don't need to delete any cache files.
jas [at] dansupport (dot) dk
29-May-2007 11:24
A general thing i've experienced with SOAP and which, for some reason, isn't mentioned in ANY tutorials I've read, is this: The server tends to cache the interface. This means that if you add a function you'll usually get errors that the function doesn't exist.
If your SOAP server is written in PHP just delete the cache files, usually located in /tmp, whenever you add a function, or modify the parameters. These are named wsdl-******something******
I hope this will spare someone the grief I've experienced with this.
Timo
03-Aug-2006 05:46
It is currently not possible to process soap headers from within a SoapServer instance. If soap headers are specified within a WSDL file, you have to extract the headers manually from the request.
For more information please see http://bugs.php.net/bug.php?id=38309
|