PHP/Network/SOAP Server

Материал из Web эксперт
Перейти к: навигация, поиск

Start soap server

 
<?php
if (! extension_loaded ( "soap" )) {
  dl ( "php_soap.dll" );
}
ini_set ( "soap.wsdl_cache_enabled", "0" );
$server = new SoapServer ( "books.wsdl" );
function doMyBookSearch($bookTitle) {
  return array ("bookTitle" => "MyBook", "bookYear" => 2005, "bookAuthor" => "s" );
}
$server->AddFunction ( "doMyBookSearch" );
$server->handle ();
?>



The SOAP Server for the getGuid() Method

 
<?php
  ini_set("soap.wsdl_cache_enabled", "Off");
  function getGuid($prefix) {
    return uniqid($prefix);
  }
  $soap = new SoapServer("guid.wsdl");
  $soap->addFunction("getGuid");
  $soap->handle();
?>



The SOAP Server Returns an Error if No Prefix Is Provided

 
<?php
  ini_set("soap.wsdl_cache_enabled", "Off");
  function getGuid($prefix) {
    if (!isset($prefix) || trim($prefix) == "") {
      throw new SoapFault("Server", "No prefix provided.");
    } else {
      return uniqid($prefix);
    }
  }
  $soap = new SoapServer("guid.wsdl");
  $soap->addFunction("getGuid");
  $soap->handle();
?>