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

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


SoapServer constructor ()

Example 2283. Some examples


= new SoapServer("some.wsdl");

$server = new SoapServer("some.wsdl", array('soap_version' => SOAP_1_2));

$server = new SoapServer("some.wsdl", array('actor' => ""));

$server = new SoapServer("some.wsdl", array('encoding'=>'ISO-8859-1'));

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

MyBook {

$server = new SoapServer("books.wsdl", array('classmap' => array('book' => "MyBook")));


Code Examples / Notes » soap_soapserver_construct


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

php dot net

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:
* Login credentials to be supplied as a SOAP header
* Class used to ensure Soap Head tags in correct format.
class SoapHeaderUsernameToken
   /** @var int Password */
   public $Password;
   /** @var int Username */
   public $Username;
   public function __construct($l, $p)
       $this->Password = $p;
       $this->Username = $l;
Now, set the Soap Headers:
// Set the login headers
$wsu = '';
$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:
$client = new SoapClient( $wsdl);
$client->__setSoapHeaders( $soapHeaders );
$client->__soapCall( $method, $params );
Moving to the Server, you'll handle the Soap call somewhat like:
// Instantiate server with relevant wsdl & class.
$server = new SoapServer( 'mysoapwsdl.wsdl' );
$server->setClass(  'mysoapclass' );
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):
class mysoapclass {
* Authentication function
* This is called by the Soap header of the same name. The function name is a Ws-security standard auth tag
* and corresponds to the header tag.
* @param string username
* @param string password
public function UsernameToken( $username, $password ){
// Store username for logging
$this->Username = $username;
$auth = new $this->AuthClass( $username, $password, get_class($this) );
if( $auth->IsValid() ){
$this->Authenticated = true;
} else {
$this->ThrowSoapFault( 'auth' );
* Test method
public function felineResponse( $action ){
// Place this at the start of every exposed method
// This is because the SoapServer will attempt to call
// if no authentication headers are passed.
$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

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.


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.

Change Language

Follow Navioo On Twitter
eXTReMe Tracker