SOAP

目录

简介

The SoapClient class provides a client for » SOAP 1.1, » SOAP 1.2 servers. It can be used in WSDL or non-WSDL mode.

类摘要

SoapClient

class SoapClient {

/* 方法 */

public mixed __call ( string $function_name , array $arguments )

public __construct ( mixed $wsdl [, array $options ] )

public string __doRequest ( string $request , string $location , string $action , int $version [, int $one_way = 0 ] )

public array __getCookies ( void )

public array __getFunctions ( void )

public string __getLastRequest ( void )

public string __getLastRequestHeaders ( void )

public string __getLastResponse ( void )

public string __getLastResponseHeaders ( void )

public array __getTypes ( void )

public void __setCookie ( string $name [, string $value ] )

public string __setLocation ([ string $new_location ] )

public bool __setSoapHeaders ([ mixed $soapheaders ] )

public mixed __soapCall ( string $function_name , array $arguments [, array $options [, mixed $input_headers [, array &$output_headers ]]] )

public SoapClient ( mixed $wsdl [, array $options ] )

}

SoapClient::__call

Calls a SOAP function (deprecated)

说明

public mixed SoapClient::__call ( string $function_name , array $arguments )

Calling this method directly is deprecated. Usually, SOAP functions can be called as methods of the SoapClient object; in situations where this is not possible or additional options are needed, use SoapClient::__soapCall.

SoapClient::__construct

SoapClient constructor

说明

public SoapClient::__construct ( mixed $wsdl [, array $options ] )

此函数是该函数的别名: SoapClient::SoapClient

SoapClient::__doRequest

Performs a SOAP request

说明

public string SoapClient::__doRequest ( string $request , string $location , string $action , int $version [, int $one_way = 0 ] )

Performs SOAP request over HTTP.

This method can be overridden in subclasses to implement different transport layers, perform additional XML processing or other purpose.

参数

request
The XML SOAP request.

location
The URL to request.

action
The SOAP action.

version
The SOAP version.

one_way
If one_way is set to 1, this method returns nothing. Use this where a response is not expected.

返回值

The XML SOAP response.

更新日志

版本说明
5.1.3The one_way parameter was added.

范例

示例 #1 SoapClient::__doRequest example

<?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, $one_way = 0) {
    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')); 
var_dump($x->Add(3,4));
?>

SoapClient::__getCookies

Get list of cookies

说明

public array SoapClient::__getCookies ( void )

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

SoapClient::__getFunctions

Returns list of available SOAP functions

说明

public array SoapClient::__getFunctions ( void )

Returns an array of functions described in the WSDL for the Web service.

Note:

此函数仅在 WSDL 模式下生效。

参数

此函数没有参数。

返回值

The array of SOAP function prototypes, detailing the return type, the function name and type-hinted parameters.

范例

示例 #1 SoapClient::__getFunctions example

<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getFunctions());
?>

以上例程会输出:

array(26) {
  [0]=>
  string(70) "ProductInfo KeywordSearchRequest(KeywordRequest $KeywordSearchRequest)"
  [1]=>
  string(79) "ProductInfo TextStreamSearchRequest(TextStreamRequest $TextStreamSearchRequest)"
  [2]=>
  string(64) "ProductInfo PowerSearchRequest(PowerRequest $PowerSearchRequest)"
...
  [23]=>
  string(107) "ShoppingCart RemoveShoppingCartItemsRequest(RemoveShoppingCartItemsRequest $RemoveShoppingCartItemsRequest)"
  [24]=>
  string(107) "ShoppingCart ModifyShoppingCartItemsRequest(ModifyShoppingCartItemsRequest $ModifyShoppingCartItemsRequest)"
  [25]=>
  string(118) "GetTransactionDetailsResponse GetTransactionDetailsRequest(GetTransactionDetailsRequest $GetTransactionDetailsRequest)"
}

参见

  • SoapClient::SoapClient

SoapClient::__getLastRequest

Returns last SOAP request

说明

public string SoapClient::__getLastRequest ( void )

Returns the XML sent in the last SOAP request.

Note:

This method works only if the class="classname">SoapClient object was created with the trace option set to TRUE.

参数

此函数没有参数。

返回值

The last SOAP request, as an XML string.

范例

示例 #1 SoapClient::__getLastRequest() example

<?php
$client = new SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
?>

参见

  • SoapClient::__getLastRequestHeaders
  • SoapClient::__getLastResponse
  • SoapClient::__getLastResponseHeaders

SoapClient::__getLastRequestHeaders

Returns the SOAP headers from the last request

说明

public string SoapClient::__getLastRequestHeaders ( void )

Returns the SOAP headers from the last request.

Note:

This function only works if the class="classname">SoapClient object was created with the trace option set to TRUE.

参数

此函数没有参数。

返回值

The last SOAP request headers.

范例

示例 #1 SoapClient::__getLastRequestHeaders() example

<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "REQUEST HEADERS:\n" . $client->__getLastRequestHeaders() . "\n";
?>

参见

  • SoapClient::__getLastResponseHeaders
  • SoapClient::__getLastRequest
  • SoapClient::__getLastResponse

SoapClient::__getLastResponse

Returns last SOAP response

说明

public string SoapClient::__getLastResponse ( void )

Returns the XML received in the last SOAP response.

Note:

This method works only if the class="classname">SoapClient object was created with the trace option set to TRUE.

参数

此函数没有参数。

返回值

The last SOAP response, as an XML string.

范例

示例 #1 SoapClient::__getLastResponse() example

<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "Response:\n" . $client->__getLastResponse() . "\n";
?>

参见

  • SoapClient::__getLastResponseHeaders
  • SoapClient::__getLastRequest
  • SoapClient::__getLastRequestHeaders

SoapClient::__getLastResponseHeaders

Returns the SOAP headers from the last response

说明

public string SoapClient::__getLastResponseHeaders ( void )

Returns the SOAP headers from the last response.

Note:

This function only works if the class="classname">SoapClient object was created with the trace option set to TRUE.

参数

此函数没有参数。

返回值

The last SOAP response headers.

范例

示例 #1 SoapClient::__getLastResponse() example

<?php
$client = SoapClient("some.wsdl", array('trace' => 1));
$result = $client->SomeFunction();
echo "RESPONSE HEADERS:\n" . $client->__getLastResponseHeaders() . "\n";
?>

参见

  • SoapClient::__getLastRequestHeaders
  • SoapClient::__getLastRequest
  • SoapClient::__getLastResponse

SoapClient::__getTypes

Returns a list of SOAP types

说明

public array SoapClient::__getTypes ( void )

Returns an array of types described in the WSDL for the Web service.

Note:

此函数仅在 WSDL 模式下生效。

参数

此函数没有参数。

返回值

The array of SOAP types, detailing all structures and types.

范例

示例 #1 SoapClient::__getTypes example

<?php
$client = new SoapClient('http://soap.amazon.com/schemas3/AmazonWebServices.wsdl');
var_dump($client->__getTypes());
?>

以上例程会输出:

array(88) {
  [0]=>
  string(30) "ProductLine ProductLineArray[]"
  [1]=>
  string(85) "struct ProductLine {
 string Mode;
 string RelevanceRank;
 ProductInfo ProductInfo;
}"
  [2]=>
  string(105) "struct ProductInfo {
 string TotalResults;
 string TotalPages;
 string ListName;
 DetailsArray Details;
}"
...
  [85]=>
  string(32) "ShortSummary ShortSummaryArray[]"
  [86]=>
  string(121) "struct GetTransactionDetailsRequest {
 string tag;
 string devtag;
 string key;
 OrderIdArray OrderIds;
 string locale;
}"
  [87]=>
  string(75) "struct GetTransactionDetailsResponse {
 ShortSummaryArray ShortSummaries;
}"
}

参见

  • SoapClient::SoapClient

SoapClient::__setCookie

The __setCookie purpose

说明

public void SoapClient::__setCookie ( string $name [, string $value ] )

Defines a cookie to be sent along with the SOAP requests.

Note:

Calling this method will affect all following calls to class="classname">SoapClient methods.

参数

name
The name of the cookie.

value
The value of the cookie. If not specified, the cookie will be deleted.

返回值

没有返回值。

SoapClient::__setLocation

Sets the location of the Web service to use

说明

public string SoapClient::__setLocation ([ string $new_location ] )

Sets the endpoint URL that will be touched by following SOAP requests. This is equivalent to specifying the location option when constructing the SoapClient.

Note:

Calling this method is optional. The SoapClient uses the endpoint from the WSDL file by default.

参数

new_location
The new endpoint URL.

返回值

The old endpoint URL.

范例

示例 #1 SoapClient::__setLocation example

<?php
$client = new SoapClient('http://example.com/webservice.php?wsdl');

$client->__setLocation('http://www.somethirdparty.com');

$old_location = $client->__setLocation(); // unsets the location option

echo $old_location;

?>

以上例程的输出类似于:

http://www.somethirdparty.com

参见

  • SoapClient::SoapClient

SoapClient::__setSoapHeaders

Sets SOAP headers for subsequent calls

说明

public bool SoapClient::__setSoapHeaders ([ mixed $soapheaders ] )

Defines headers to be sent along with the SOAP requests.

Note:

Calling this method will replace any previous values.

参数

soapheaders
The headers to be set. It could be SoapHeader object or array of SoapHeader objects. If not specified or set to NULL, the headers will be deleted.

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

示例 #1 SoapClient::__setSoapHeaders example

<?php

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));
$header = new SoapHeader('http://soapinterop.org/echoheader/', 
                            'echoMeStringRequest',
                            'hello world');

$client->__setSoapHeaders($header);

$client->__soapCall("echoVoid", null);
?>

示例 #2 Set Multiple Headers

<?php

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));
$headers = array();

$headers[] = new SoapHeader('http://soapinterop.org/echoheader/', 
                            'echoMeStringRequest',
                            'hello world');

$headers[] = new SoapHeader('http://soapinterop.org/echoheader/', 
                            'echoMeStringRequest',
                            'hello world again');

$client->__setSoapHeaders($headers);

$client->__soapCall("echoVoid", null);
?>

SoapClient::__soapCall

Calls a SOAP function

说明

public mixed SoapClient::__soapCall ( string $function_name , array $arguments [, array $options [, mixed $input_headers [, array &$output_headers ]]] )

This is a low level API function that is used to make a SOAP call. Usually, in WSDL mode, SOAP functions can be called as methods of the SoapClient object. This method is useful in non-WSDL mode when soapaction is unknown, uri differs from the default or when sending and/or receiving SOAP Headers.

On error, a call to a SOAP function can cause PHP to throw exceptions or return a SoapFault object if exceptions are disabled. To check if the function call failed to catch the SoapFault exceptions, check the result with is_soap_fault.

参数

function_name
The name of the SOAP function to call.

arguments
An array of the arguments to pass to the function. This can be either an ordered or an associative array. Note that most SOAP servers require parameter names to be provided, in which case this must be an associative array.

options
An associative array of options to pass to the client.

The location option is the URL of the remote Web service.

The uri option is the target namespace of the SOAP service.

The soapaction option is the action to call.

input_headers
An array of headers to be sent along with the SOAP request.

output_headers
If supplied, this array will be filled with the headers from the SOAP response.

返回值

SOAP functions may return one, or multiple values. If only one value is returned by the SOAP function, the return value of __soapCall will be a simple value (e.g. an integer, a string, etc). If multiple values are returned, __soapCall will return an associative array of named output parameters.

On error, if the SoapClient object was constructed with the exceptions option set to FALSE, a SoapFault object will be returned.

范例

示例 #1 SoapClient::__soapCall example

<?php

$client = new SoapClient("some.wsdl");
$client->SomeFunction($a, $b, $c);

$client->__soapCall("SomeFunction", array($a, $b, $c));
$client->__soapCall("SomeFunction", array($a, $b, $c), NULL,
                    new SoapHeader(), $output_headers);


$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));
$client->SomeFunction($a, $b, $c);
$client->__soapCall("SomeFunction", array($a, $b, $c));
$client->__soapCall("SomeFunction", array($a, $b, $c),
                    array('soapaction' => 'some_action',
                          'uri'        => 'some_uri'));
?>

参见

  • SoapClient::SoapClient
  • SoapParam::SoapParam
  • SoapVar::SoapVar
  • SoapHeader::SoapHeader
  • SoapFault::SoapFault
  • is_soap_fault

SoapClient::SoapClient

SoapClient constructor

说明

public SoapClient::SoapClient ( mixed $wsdl [, array $options ] )

This constructor creates SoapClient objects in WSDL or non-WSDL mode.

参数

wsdl
URI of the WSDL file or NULL if working in non-WSDL mode.

Note:

During development, WSDL caching may be disabled by the use of the soap.wsdl_cache_ttl php.ini setting otherwise changes made to the WSDL file will have no effect until soap.wsdl_cache_ttl is expired.

options
An array of options. If working in WSDL mode, this parameter is optional. If working in non-WSDL mode, the location and uri options must be set, where location is the URL of the SOAP server to send the request to, and uri is the target namespace of the SOAP service.

The style and use options only work in non-WSDL mode. In WSDL mode, they come from the WSDL file.

The soap_version option should be one of either SOAP_1_1 or SOAP_1_2 to select SOAP 1.1 or 1.2, respectively. If omitted, 1.1 is used.

For HTTP authentication, the login and password options can be used to supply credentials. For making an HTTP connection through a proxy server, the options proxy_host, proxy_port, proxy_login and proxy_password are also available. For HTTPS client certificate authentication use local_cert and passphrase options. An authentication may be supplied in the authentication option. The authentication method may be either SOAP_AUTHENTICATION_BASIC (default) or SOAP_AUTHENTICATION_DIGEST.

The compression option allows to use compression of HTTP SOAP requests and responses.

The encoding option defines internal character encoding. This option does not change the encoding of SOAP requests (it is always utf-8), but converts strings into it.

The trace option enables tracing of request so faults can be backtraced. This defaults to FALSE

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.

Setting the boolean trace option enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders.

The exceptions option is a boolean value defining whether soap errors throw exceptions of type SoapFault.

The connection_timeout option defines a timeout in seconds for the connection to the SOAP service. This option does not define a timeout for services with slow responses. To limit the time to wait for calls to finish the default_socket_timeout setting is available.

The typemap option is an array of type mappings. Type mapping is an array with keys type_name, type_ns (namespace URI), from_xml (callback accepting one string parameter) and to_xml (callback accepting one object parameter).

The cache_wsdl option is one of WSDL_CACHE_NONE, WSDL_CACHE_DISK, WSDL_CACHE_MEMORY or WSDL_CACHE_BOTH.

The user_agent option specifies string to use in User-Agent header.

The stream_context option is a resource for context.

The features option is a bitmask of SOAP_SINGLE_ELEMENT_ARRAYS, SOAP_USE_XSI_ARRAY_TYPE, SOAP_WAIT_ONE_WAY_CALLS.

The keep_alive option is a boolean value defining whether to send the Connection: Keep-Alive header or Connection: close.

The ssl_method option is one of SOAP_SSL_METHOD_TLS, SOAP_SSL_METHOD_SSLv2, SOAP_SSL_METHOD_SSLv3 or SOAP_SSL_METHOD_SSLv23.

错误/异常

SoapClient::SoapClient will generate an E_ERROR error if the location and uri options aren't provided in non-WSDL mode.

A SoapFault exception will be thrown if the wsdl URI cannot be loaded.

更新日志

版本说明
5.5.0New ssl_method option.
5.4.0New keep_alive option.

范例

示例 #1 SoapClient::SoapClient example

<?php

$client = new SoapClient("some.wsdl");

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

$client = new SoapClient("some.wsdl", array('login'          => "some_name",
                                            'password'       => "some_password"));

$client = new SoapClient("some.wsdl", array('proxy_host'     => "localhost",
                                            'proxy_port'     => 8080));

$client = new SoapClient("some.wsdl", array('proxy_host'     => "localhost",
                                            'proxy_port'     => 8080,
                                            'proxy_login'    => "some_name",
                                            'proxy_password' => "some_password"));

$client = new SoapClient("some.wsdl", array('local_cert'     => "cert_key.pem"));

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));

$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/",
                                     'style'    => SOAP_DOCUMENT,
                                     'use'      => SOAP_LITERAL));

$client = new SoapClient("some.wsdl", 
  array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP));

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

class MyBook {
    public $title;
    public $author;
}

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

?>

简介

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.

类摘要

SoapServer

class SoapServer {

/* 方法 */

public void addFunction ( mixed $functions )

public void addSoapHeader ( SoapHeader $object )

public __construct ( mixed $wsdl [, array $options ] )

public void fault ( string $code , string $string [, string $actor [, string $details [, string $name ]]] )

public array getFunctions ( void )

public void handle ([ string $soap_request ] )

public void setClass ( string $class_name [, mixed $... ] )

public void setObject ( object $object )

public void setPersistence ( int $mode )

public SoapServer ( mixed $wsdl [, array $options ] )

}

SoapServer::addFunction

添加一个或多个函数来处理SOAP请求

说明

public void SoapServer::addFunction ( mixed $functions )

为远程客户端导出一个或多个函数

参数

functions
导出一个函数,将函数名作为字符串传递给这个参数。

导出多个函数,将一组函数名作为数组传递。

导出所有函数,传递特殊常量 SOAP_FUNCTIONS_ALL.

Note:

functions 接收的所有输入参数必须同时和WSDL文件中定义的 顺序一样(它们不应该接收任何输出变量作为参数)并且返回一个或多个值。如果要返回多个 值,它们必须返回一组被命名的输出参数作为数组。

返回值

没有返回值。

范例

示例 #1 SoapServer::addFunction example

<?php

function echoString($inputString)
{
    return $inputString;
}

$server->addFunction("echoString");

function echoTwoStrings($inputString1, $inputString2)
{
    return array("outputString1" => $inputString1,
                 "outputString2" => $inputString2);
}
$server->addFunction(array("echoString", "echoTwoStrings"));

$server->addFunction(SOAP_FUNCTIONS_ALL);

?>

参见

  • SoapServer::SoapServer
  • SoapServer::setClass

SoapServer::addSoapHeader

Add a SOAP header to the response

说明

public void SoapServer::addSoapHeader ( SoapHeader $object )

Adds a SOAP header to be returned with the response to the current request.

参数

object
The header to be returned.

返回值

没有返回值。

SoapServer::__construct

SoapServer constructor

说明

public SoapServer::__construct ( mixed $wsdl [, array $options ] )

此函数是该函数的别名: SoapServer::SoapServer

SoapServer::fault

Issue SoapServer fault indicating an error

说明

public void SoapServer::fault ( string $code , string $string [, string $actor [, string $details [, string $name ]]] )

Sends a response to the client of the current request indicating an error.

Note:

This can only be called when handling a request.

参数

code
The error code to return

string
A brief description of the error

actor
A string identifying the actor that caused the fault.

details
More details of the fault

name
The name of the fault. This can be used to select a name from a WSDL file.

返回值

没有返回值。

参见

  • SoapFault::SoapFault

SoapServer::getFunctions

Returns list of defined functions

说明

public array SoapServer::getFunctions ( void )

Returns a list of the defined functions in the SoapServer object. This method returns the list of all functions added by SoapServer::addFunction or SoapServer::setClass.

参数

此函数没有参数。

返回值

An array of the defined functions.

范例

示例 #1 SoapServer::getFunctions example

<?php
$server = new SoapServer(NULL, array("uri" => "http://test-uri"));
$server->addFunction(SOAP_FUNCTIONS_ALL);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $server->handle();
} else {
  echo "This SOAP server can handle following functions: ";
  $functions = $server->getFunctions();
  foreach($functions as $func) {
    echo $func . "\n";
  }
}
?>

参见

  • SoapServer::SoapServer
  • SoapServer::addFunction
  • SoapServer::setClass

SoapServer::handle

Handles a SOAP request

说明

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

Processes a SOAP request, calls necessary functions, and sends a response back.

参数

soap_request
The SOAP request. If this argument is omitted, the request is assumed to be in the raw POST data of the HTTP request.

返回值

没有返回值。

范例

示例 #1 SoapServer::handle example

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

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

参见

  • SoapServer::SoapServer

SoapServer::setClass

Sets the class which handles SOAP requests

说明

public void SoapServer::setClass ( string $class_name [, mixed $... ] )

Exports all methods from specified class.

The object can be made persistent across request for a given PHP session with the SoapServer::setPersistence method.

参数

class_name
The name of the exported class.

...
These optional parameters will be passed to the default class constructor during object creation.

返回值

没有返回值。

参见

  • SoapServer::SoapServer
  • SoapServer::addFunction
  • SoapServer::setPersistence

SoapServer::setObject

Sets the object which will be used to handle SOAP requests

说明

public void SoapServer::setObject ( object $object )

This sets a specific object as the handler for SOAP requests, rather than just a class as in SoapServer::setClass.

参数

object
The object to handle the requests.

返回值

没有返回值。

参见

  • SoapServer::setClass

SoapServer::setPersistence

Sets SoapServer persistence mode

说明

public void SoapServer::setPersistence ( int $mode )

This function allows changing the persistence state of a SoapServer object between requests. This function allows saving data between requests utilizing PHP sessions. This method only has an affect on a SoapServer after it has exported functions utilizing SoapServer::setClass.

Note:

The persistence of SOAP_PERSISTENCE_SESSION makes only objects of the given class persistent, but not the class static data. In this case, use $this->bar instead of self::$bar.

Note:

SOAP_PERSISTENCE_SESSION serializes data on the class object between requests. In order to properly utilize resources (e.g. class="classname">PDO), __wakeup() and __sleep() magic methods should be utilized.

参数

mode
One of the SOAP_PERSISTENCE_XXX constants.

SOAP_PERSISTENCE_REQUEST - SoapServer data does not persist between requests. This is the default behavior of any SoapServer object after setClass is called.

SOAP_PERSISTENCE_SESSION - SoapServer data persists between requests. This is accomplished by serializing the SoapServer class data into $_SESSION['_bogus_session_name'], because of this session_start must be called before this persistence mode is set.

返回值

没有返回值。

范例

示例 #1 SoapServer::setPersistence example

<?php
 class MyFirstPersistentSoapServer {
     private $resource; // (Such as PDO, mysqli, etc..)
     public $myvar1;
     public $myvar2;

     public function __construct() {
         $this->__wakeup(); // We're calling our wakeup to handle starting our resource
     }

     public function __wakeup() {
         $this->resource = CodeToStartOurResourceUp();
     }

     public function __sleep() {
         // We make sure to leave out $resource here, so our session data remains persistent
         // Failure to do so will result in the failure during the unserialization of data
         // on the next request; thus, our SoapObject would not be persistent across requests.
         return array('myvar1','myvar2');
     }
 }

 try {
     session_start();
     $server = new SoapServer(null, array('uri' => $_SERVER['REQUEST_URI']));
     $server->setClass('MyFirstPersistentSoapServer');
     // setPersistence MUST be called after setClass, because setClass's
     // behavior sets SESSION_PERSISTENCE_REQUEST upon enacting the method.
     $server->setPersistence(SOAP_PERSISTENCE_SESSION);
     $server->handle();
 } catch(SoapFault $e) {
     error_log("SOAP ERROR: ". $e->getMessage());
 }
?>

参见

  • SoapServer::setClass

SoapServer::SoapServer

SoapServer constructor

说明

public SoapServer::SoapServer ( mixed $wsdl [, array $options ] )

This constructor allows the creation of SoapServer objects in WSDL or non-WSDL mode.

参数

wsdl
To use the SoapServer in WSDL mode, pass the URI of a WSDL file. Otherwise, pass NULL and set the uri option to the target namespace for the server.

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.

The typemap option is an array of type mappings. Type mapping is an array with keys type_name, type_ns (namespace URI), from_xml (callback accepting one string parameter) and to_xml (callback accepting one object parameter).

The cache_wsdl option is one of WSDL_CACHE_NONE, WSDL_CACHE_DISK, WSDL_CACHE_MEMORY or WSDL_CACHE_BOTH.

There is also a features option which can be set to SOAP_WAIT_ONE_WAY_CALLS, SOAP_SINGLE_ELEMENT_ARRAYS, SOAP_USE_XSI_ARRAY_TYPE.

The send_errors option can be set to FALSE to sent a generic error message ("Internal error") instead of the specific error message sent otherwise.

范例

示例 #1 SoapServer::SoapServer example

<?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")));

?>

更新日志

版本说明
5.2.0Added the typemap option.

参见

  • SoapClient::SoapClient

简介

Represents a SOAP fault.

类摘要

SoapFault

class SoapFault extends Exception {

/* 继承的属性 */

protected string $message ;

protected int $code ;

protected string $file ;

protected int $line ;

/* 方法 */

__construct ( string $faultcode , string $faultstring [, string $faultactor [, string $detail [, string $faultname [, string $headerfault ]]]] )

SoapFault ( string $faultcode , string $faultstring [, string $faultactor [, string $detail [, string $faultname [, string $headerfault ]]]] )

public string __toString ( void )

/* 继承的方法 */

final public string Exception::getMessage ( void )

final public Throwable Exception::getPrevious ( void )

final public int Exception::getCode ( void )

final public string Exception::getFile ( void )

final public int Exception::getLine ( void )

final public array Exception::getTrace ( void )

final public string Exception::getTraceAsString ( void )

public string Exception::__toString ( void )

final private void Exception::__clone ( void )

}

SoapFault::__construct

SoapFault constructor

说明

SoapFault::__construct ( string $faultcode , string $faultstring [, string $faultactor [, string $detail [, string $faultname [, string $headerfault ]]]] )

此函数是该函数的别名: SoapFault::SoapFault

SoapFault::SoapFault

SoapFault constructor

说明

SoapFault::SoapFault ( string $faultcode , string $faultstring [, string $faultactor [, string $detail [, string $faultname [, string $headerfault ]]]] )

This class is used to send SOAP fault responses from the PHP handler. faultcode, faultstring, faultactor and detail are standard elements of a SOAP Fault.

参数

faultcode
The error code of the SoapFault.

faultstring
The error message of the SoapFault.

faultactor
A string identifying the actor that caused the error.

detail
More details about the cause of the error.

faultname
Can be used to select the proper fault encoding from WSDL.

headerfault
Can be used during SOAP header handling to report an error in the response header.

范例

示例 #1 Some examples

<?php
function test($x)
{
    return new SoapFault("Server", "Some error message");
}

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

It is possible to use PHP exception mechanism to throw SOAP Fault.

示例 #2 Some examples

<?php
function test($x)
{
    throw new SoapFault("Server", "Some error message");
}

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

参见

  • SoapServer::fault
  • is_soap_fault

SoapFault::__toString

Obtain a string representation of a SoapFault

说明

public string SoapFault::__toString ( void )

Returns a string representation of the SoapFault.

参数

此函数没有参数。

返回值

A string describing the SoapFault.

简介

Represents a SOAP header.

类摘要

SoapHeader

class SoapHeader {

/* 方法 */

__construct ( string $namespace , string $name [, mixed $data [, bool $mustunderstand [, string $actor ]]] )

SoapHeader ( string $namespace , string $name [, mixed $data [, bool $mustunderstand = FALSE [, string $actor ]]] )

}

SoapHeader::__construct

SoapHeader constructor

说明

SoapHeader::__construct ( string $namespace , string $name [, mixed $data [, bool $mustunderstand [, string $actor ]]] )

此函数是该函数的别名: SoapHeader::SoapHeader

SoapHeader::SoapHeader

SoapHeader constructor

说明

SoapHeader::SoapHeader ( string $namespace , string $name [, mixed $data [, bool $mustunderstand = FALSE [, string $actor ]]] )

Constructs a new SoapHeader object.

参数

namespace
The namespace of the SOAP header element.

name
The name of the SoapHeader object.

data
A SOAP header's content. It can be a PHP value or a SoapVar object.

mustUnderstand
Value of the mustUnderstand attribute of the SOAP header element.

actor
Value of the actor attribute of the SOAP header element.

范例

示例 #1 SoapHeader::SoapHeader example

<?php
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));
$client->__soapCall("echoVoid", null, null,
                new SoapHeader('http://soapinterop.org/echoheader/',
                               'echoMeStringRequest',
                               'hello world'));
?>

参见

  • SoapClient::__soapCall
  • SoapVar::SoapVar
  • SoapParam::SoapParam
  • SoapServer::addSoapHeader

简介

Represents parameter to a SOAP call.

类摘要

SoapParam

class SoapParam {

/* 方法 */

__construct ( mixed $data , string $name )

SoapParam ( mixed $data , string $name )

}

SoapParam::__construct

SoapParam constructor

说明

SoapParam::__construct ( mixed $data , string $name )

此函数是该函数的别名: SoapParam::SoapParam

SoapParam::SoapParam

SoapParam constructor

说明

SoapParam::SoapParam ( mixed $data , string $name )

Constructs a new SoapParam object.

参数

data
The data to pass or return. This parameter can be passed directly as PHP value, but in this case it will be named as paramN and the SOAP service may not understand it.

name
The parameter name.

范例

示例 #1 SoapParam::SoapParam example

<?php
$client = new SoapClient(null,array('location' => "http://localhost/soap.php",
                                    'uri'      => "http://test-uri/"));
$client->SomeFunction(new SoapParam($a, "a"),
                      new SoapParam($b, "b"),
                      new SoapParam($c, "c"));
?>

参见

  • SoapClient::__soapCall
  • SoapVar::SoapVar

简介

A class representing a variable or object for use with SOAP services.

类摘要

SoapVar

class SoapVar {

/* 方法 */

__construct ( mixed $data , string $encoding [, string $type_name [, string $type_namespace [, string $node_name [, string $node_namespace ]]]] )

SoapVar ( mixed $data , string $encoding [, string $type_name [, string $type_namespace [, string $node_name [, string $node_namespace ]]]] )

}

SoapVar::__construct

SoapVar constructor

说明

SoapVar::__construct ( mixed $data , string $encoding [, string $type_name [, string $type_namespace [, string $node_name [, string $node_namespace ]]]] )

此函数是该函数的别名: SoapVar::SoapVar

SoapVar::SoapVar

SoapVar constructor

说明

SoapVar::SoapVar ( mixed $data , string $encoding [, string $type_name [, string $type_namespace [, string $node_name [, string $node_namespace ]]]] )

Constructs a new SoapVar object.

参数

data
The data to pass or return.

encoding
The encoding ID, one of the XSD_... constants.

type_name
The type name.

type_namespace
The type namespace.

node_name
The XML node name.

node_namespace
The XML node namespace.

范例

示例 #1 SoapVar::SoapVar example

<?php
class SOAPStruct {
    function SOAPStruct($s, $i, $f) 
    {
        $this->varString = $s;
        $this->varInt = $i;
        $this->varFloat = $f;
    }
}
$client = new SoapClient(null, array('location' => "http://localhost/soap.php",
                                     'uri'      => "http://test-uri/"));
$struct = new SOAPStruct('arg', 34, 325.325);
$soapstruct = new SoapVar($struct, SOAP_ENC_OBJECT, "SOAPStruct", "http://soapinterop.org/xsd");
$client->echoStruct(new SoapParam($soapstruct, "inputStruct"));
?>

参见

  • SoapClient::__soapCall
  • SoapParam::SoapParam