Book/soap-Phpdoc专题
SOAP
目录
- 简介
- 安装/配置
- 预定义常量
- SOAP 函数
- is_soap_fault — Checks if a SOAP call has failed
- use_soap_error_handler — Set whether to use the SOAP error handler
- SoapClient — The SoapClient class
- SoapClient::__call — Calls a SOAP function (deprecated)
- SoapClient::__construct — SoapClient constructor
- SoapClient::__doRequest — Performs a SOAP request
- SoapClient::__getCookies — Get list of cookies
- SoapClient::__getFunctions — Returns list of available SOAP functions
- SoapClient::__getLastRequest — Returns last SOAP request
- SoapClient::__getLastRequestHeaders — Returns the SOAP headers from the last request
- SoapClient::__getLastResponse — Returns last SOAP response
- SoapClient::__getLastResponseHeaders — Returns the SOAP headers from the last response
- SoapClient::__getTypes — Returns a list of SOAP types
- SoapClient::__setCookie — The __setCookie purpose
- SoapClient::__setLocation — Sets the location of the Web service to use
- SoapClient::__setSoapHeaders — Sets SOAP headers for subsequent calls
- SoapClient::__soapCall — Calls a SOAP function
- SoapClient::SoapClient — SoapClient constructor
- SoapServer — The SoapServer class
- SoapServer::addFunction — 添加一个或多个函数来处理SOAP请求
- SoapServer::addSoapHeader — Add a SOAP header to the response
- SoapServer::__construct — SoapServer constructor
- SoapServer::fault — Issue SoapServer fault indicating an error
- SoapServer::getFunctions — Returns list of defined functions
- SoapServer::handle — Handles a SOAP request
- SoapServer::setClass — Sets the class which handles SOAP requests
- SoapServer::setObject — Sets the object which will be used to handle SOAP requests
- SoapServer::setPersistence — Sets SoapServer persistence mode
- SoapServer::SoapServer — SoapServer constructor
- SoapFault — The SoapFault class
- SoapFault::__construct — SoapFault constructor
- SoapFault::SoapFault — SoapFault constructor
- SoapFault::__toString — Obtain a string representation of a SoapFault
- SoapHeader — The SoapHeader class
- SoapHeader::__construct — SoapHeader constructor
- SoapHeader::SoapHeader — SoapHeader constructor
- SoapParam — The SoapParam class
- SoapParam::__construct — SoapParam constructor
- SoapParam::SoapParam — SoapParam constructor
- SoapVar — The SoapVar class
- SoapVar::__construct — SoapVar constructor
- SoapVar::SoapVar — SoapVar constructor
简介
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 <span
class="methodname">__construct ( <span
class="methodparam"><span
class="type">stringnull
$wsdl [, <span
class="type">array $options =
[] ] )
public mixed
__call ( <span
class="methodparam">string $name ,
array $args
)
public <span
class="type">stringnull <span
class="methodname">__doRequest ( <span
class="methodparam">string $request ,
string
$location , <span
class="type">string $action , <span
class="methodparam">int $version [,
bool $oneWay<span
class="initializer"> = false ] )
public array __getCookies ( <span class="methodparam">void )
public <span class="type">arraynull <span class="methodname">__getFunctions ( <span class="methodparam">void )
public <span class="type">stringnull <span class="methodname">__getLastRequest ( <span class="methodparam">void )
public <span class="type">stringnull <span class="methodname">__getLastRequestHeaders ( <span class="methodparam">void )
public <span class="type">stringnull <span class="methodname">__getLastResponse ( <span class="methodparam">void )
public <span class="type">stringnull <span class="methodname">__getLastResponseHeaders ( <span class="methodparam">void )
public <span class="type">arraynull <span class="methodname">__getTypes ( <span class="methodparam">void )
public void
__setCookie ( <span
class="methodparam">string $name [,
<span
class="type">stringnull
$value = null ] )
public <span
class="type">stringnull <span
class="methodname">__setLocation ([ <span
class="methodparam">string $location<span
class="initializer"> = "" ] )
public bool
__setSoapHeaders ([ <span
class="methodparam"><span
class="type">SoapHeaderarray<span
class="type">null $headers =
null ] )
public mixed
__soapCall ( <span
class="methodparam">string $name ,
array $args
[, <span
class="type">arraynull
$options = null [,
<span
class="type">SoapHeaderarray<span
class="type">null $inputHeaders<span
class="initializer"> = null [, <span
class="methodparam">array
&$outputHeaders = null
]]] )
public <span
class="methodname">SoapClient ( <span
class="type">mixed $wsdl [, <span
class="methodparam">array $options ]
)
}
SoapClient::__call
Calls a SOAP function (deprecated)
说明
public mixed
SoapClient::__call ( <span
class="methodparam">string $name ,
array $args
)
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 <span
class="methodname">SoapClient::__construct ( <span
class="methodparam"><span
class="type">stringnull
$wsdl [, <span
class="type">array $options =
[] ] )
此函数是该函数的别名: <span class="methodname">SoapClient::SoapClient
SoapClient::__doRequest
Performs a SOAP request
说明
public <span
class="type">stringnull <span
class="methodname">SoapClient::__doRequest ( <span
class="methodparam">string $request ,
string
$location , <span
class="type">string $action , <span
class="methodparam">int $version [,
bool $oneWay<span
class="initializer"> = false ] )
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.
oneWay
If one_way is set to 1, this method returns nothing. Use this where a
response is not expected.
返回值
The XML SOAP response.
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 | The type of oneWay is bool now; formerly it was int. |
范例
示例 #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 ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
SoapClient::__getFunctions
Returns list of available SOAP functions
说明
public <span class="type">arraynull <span class="methodname">SoapClient::__getFunctions ( <span class="methodparam">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 <span class="type">stringnull <span class="methodname">SoapClient::__getLastRequest ( <span class="methodparam">void )
Returns the XML sent in the last SOAP request.
Note:
This method works only if the <span 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";
?>
参见
- <span class="methodname">SoapClient::__getLastRequestHeaders
- SoapClient::__getLastResponse
- <span class="methodname">SoapClient::__getLastResponseHeaders
SoapClient::__getLastRequestHeaders
Returns the SOAP headers from the last request
说明
public <span class="type">stringnull <span class="methodname">SoapClient::__getLastRequestHeaders ( <span class="methodparam">void )
Returns the SOAP headers from the last request.
Note:
This function only works if the <span 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";
?>
参见
- <span class="methodname">SoapClient::__getLastResponseHeaders
- SoapClient::__getLastRequest
- SoapClient::__getLastResponse
SoapClient::__getLastResponse
Returns last SOAP response
说明
public <span class="type">stringnull <span class="methodname">SoapClient::__getLastResponse ( <span class="methodparam">void )
Returns the XML received in the last SOAP response.
Note:
This method works only if the <span 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";
?>
参见
- <span class="methodname">SoapClient::__getLastResponseHeaders
- SoapClient::__getLastRequest
- <span class="methodname">SoapClient::__getLastRequestHeaders
SoapClient::__getLastResponseHeaders
Returns the SOAP headers from the last response
说明
public <span class="type">stringnull <span class="methodname">SoapClient::__getLastResponseHeaders ( <span class="methodparam">void )
Returns the SOAP headers from the last response.
Note:
This function only works if the <span 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";
?>
参见
- <span class="methodname">SoapClient::__getLastRequestHeaders
- SoapClient::__getLastRequest
- SoapClient::__getLastResponse
SoapClient::__getTypes
Returns a list of SOAP types
说明
public <span class="type">arraynull <span class="methodname">SoapClient::__getTypes ( <span class="methodparam">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 ( <span
class="methodparam">string $name [,
<span
class="type">stringnull
$value = null ] )
Defines a cookie to be sent along with the SOAP requests.
Note:
Calling this method will affect all following calls to <span class="classname">SoapClient methods.
参数
name
The name of the cookie.
value
The value of the cookie. If not specified, the cookie will be deleted.
返回值
没有返回值。
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 | value is now nullable. |
SoapClient::__setLocation
Sets the location of the Web service to use
说明
public <span
class="type">stringnull <span
class="methodname">SoapClient::__setLocation ([ <span
class="methodparam">string $location<span
class="initializer"> = "" ] )
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.
参数
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 ([ <span
class="methodparam"><span
class="type">SoapHeaderarray<span
class="type">null $headers =
null ] )
Defines headers to be sent along with the SOAP requests.
Note:
Calling this method will replace any previous values.
参数
headers
The headers to be set. It could be <span
class="classname">SoapHeader object or array of <span
class="classname">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 ( <span
class="methodparam">string $name ,
array $args
[, <span
class="type">arraynull
$options = null [,
<span
class="type">SoapHeaderarray<span
class="type">null $inputHeaders<span
class="initializer"> = null [, <span
class="methodparam">array
&$outputHeaders = null
]]] )
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 <span class="function">is_soap_fault.
参数
name
The name of the SOAP function to call.
args
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.
inputHeaders
An array of headers to be sent along with the SOAP request.
outputHeaders
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 <span
class="methodname">SoapClient::SoapClient ( <span
class="methodparam">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.inisetting 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, <a href="/class/soapclient.html#SoapClient::getLastRequestHeaders" class="link">SoapClient->getLastRequestHeaders, <a href="/class/soapclient.html#SoapClient::getLastResponse" class="link">SoapClient->getLastResponse and <a href="/class/soapclient.html#SoapClient::getLastResponseHeaders" class="link">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.
范例
示例 #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 <span
class="methodname">__construct ( <span
class="methodparam"><span
class="type">stringnull
$wsdl [, <span
class="type">array $options =
[] ] )
public void
addFunction ( <span
class="methodparam">mixed $functions
)
public void
addSoapHeader ( <span
class="methodparam">SoapHeader
$header )
public void
fault ( <span
class="type">string $code , <span
class="methodparam">string $string
[, string
$actor = "" [, <span
class="methodparam">mixed $details<span
class="initializer"> = null [, <span
class="methodparam">string $name<span
class="initializer"> = "" ]]] )
public array getFunctions ( <span class="methodparam">void )
public void
handle ([ <span
class="methodparam"><span
class="type">stringnull
$request = null ] )
public void
setClass ( <span
class="methodparam">string $class ,
mixed $args
)
public void
setObject ( <span
class="methodparam">object $object )
public void
setPersistence ( <span
class="methodparam">int $mode )
public <span
class="methodname">SoapServer ( <span
class="type">mixed $wsdl [, <span
class="methodparam">array $options ]
)
}
SoapServer::addFunction
添加一个或多个函数来处理SOAP请求
说明
public void
SoapServer::addFunction ( <span
class="methodparam">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 ( <span
class="methodparam">SoapHeader
$header )
Adds a SOAP header to be returned with the response to the current request.
参数
header
The header to be returned.
返回值
没有返回值。
SoapServer::__construct
SoapServer constructor
说明
public <span
class="methodname">SoapServer::__construct ( <span
class="methodparam"><span
class="type">stringnull
$wsdl [, <span
class="type">array $options =
[] ] )
此函数是该函数的别名: <span class="methodname">SoapServer::SoapServer
SoapServer::fault
Issue SoapServer fault indicating an error
说明
public void
SoapServer::fault ( <span
class="methodparam">string $code ,
string
$string [, <span
class="type">string $actor =
"" [, <span
class="type">mixed $details =
null [, <span
class="type">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 ( <span class="methodparam">void )
Returns a list of the defined functions in the SoapServer object. This method returns the list of all functions added by <span class="methodname">SoapServer::addFunction or <span class="methodname">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 ([ <span
class="methodparam"><span
class="type">stringnull
$request = null ] )
Processes a SOAP request, calls necessary functions, and sends a response back.
参数
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();
?>
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 | request is now nullable. |
参见
- SoapServer::SoapServer
SoapServer::setClass
Sets the class which handles SOAP requests
说明
public void
SoapServer::setClass ( <span
class="methodparam">string $class ,
mixed $args
)
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
The name of the exported class.
args
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 ( <span
class="methodparam">object $object )
This sets a specific object as the handler for SOAP requests, rather than just a class as in <span class="methodname">SoapServer::setClass.
参数
object
The object to handle the requests.
返回值
没有返回值。
参见
- SoapServer::setClass
SoapServer::setPersistence
Sets SoapServer persistence mode
说明
public void
SoapServer::setPersistence ( <span
class="methodparam">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 <span class="methodname">SoapServer::setClass.
Note:
The persistence of
SOAP_PERSISTENCE_SESSIONmakes only objects of the given class persistent, but not the class static data. In this case, use$this->barinstead of self::$bar.
Note:
SOAP_PERSISTENCE_SESSIONserializes data on the class object between requests. In order to properly utilize resources (e.g. <span 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 <span
class="function">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 <span
class="methodname">SoapServer::SoapServer ( <span
class="methodparam">mixed $wsdl [,
array
$options ] )
This constructor allows the creation of <span class="classname">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")));
?>
参见
- SoapClient::SoapClient
简介
Represents a SOAP fault.
类摘要
SoapFault
class SoapFault <span class="ooclass"> extends Exception {
/* 继承的属性 */
protected string
$message ;
protected int
$code ;
protected string
$file ;
protected int
$line ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam"><span
class="type">arraystring<span
class="type">null $code , <span
class="methodparam">string $string
[, <span
class="type">stringnull
$actor = null [, <span
class="methodparam">mixed $details<span
class="initializer"> = null [, <span
class="methodparam"><span
class="type">stringnull
$name = null [, <span
class="methodparam">mixed $headerFault<span
class="initializer"> = null ]]]] )
SoapFault ( <span
class="methodparam">string $faultcode
, string
$faultstring [, <span
class="type">string $faultactor [, <span
class="methodparam">string $detail
[, string
$faultname [, <span
class="type">string $headerfault ]]]] )
public string __toString ( <span class="methodparam">void )
/* 继承的方法 */
final public string <span class="methodname">Exception::getMessage ( <span class="methodparam">void )
final public Throwable <span class="methodname">Exception::getPrevious ( <span class="methodparam">void )
final public mixed <span class="methodname">Exception::getCode ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getFile ( <span class="methodparam">void )
final public int <span class="methodname">Exception::getLine ( <span class="methodparam">void )
final public array <span class="methodname">Exception::getTrace ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getTraceAsString ( <span class="methodparam">void )
public string Exception::__toString ( <span class="methodparam">void )
final <span class="modifier">private void <span class="methodname">Exception::__clone ( <span class="methodparam">void )
}
SoapFault::__construct
SoapFault constructor
说明
public <span
class="methodname">SoapFault::__construct ( <span
class="methodparam"><span
class="type">arraystring<span
class="type">null $code , <span
class="methodparam">string $string
[, <span
class="type">stringnull
$actor = null [, <span
class="methodparam">mixed $details<span
class="initializer"> = null [, <span
class="methodparam"><span
class="type">stringnull
$name = null [, <span
class="methodparam">mixed $headerFault<span
class="initializer"> = null ]]]] )
此函数是该函数的别名: <span class="methodname">SoapFault::SoapFault
SoapFault::SoapFault
SoapFault constructor
说明
SoapFault::SoapFault ( <span
class="methodparam">string $faultcode
, string
$faultstring [, <span
class="type">string $faultactor [, <span
class="methodparam">string $detail
[, string
$faultname [, <span
class="type">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 ( <span class="methodparam">void )
Returns a string representation of the SoapFault.
参数
此函数没有参数。
返回值
A string describing the SoapFault.
简介
Represents a SOAP header.
类摘要
SoapHeader
class SoapHeader {
/* 方法 */
__construct ( <span
class="methodparam">string $namespace
, string
$name [, <span
class="type">mixed $data [, <span
class="methodparam">bool
$mustunderstand [, <span
class="type">string $actor ]]] )
SoapHeader ( <span
class="methodparam">string $namespace
, string
$name [, <span
class="type">mixed $data [, <span
class="methodparam">bool
$mustunderstand = false
[, string
$actor ]]] )
}
SoapHeader::__construct
SoapHeader constructor
说明
SoapHeader::__construct ( <span
class="methodparam">string $namespace
, string
$name [, <span
class="type">mixed $data [, <span
class="methodparam">bool
$mustunderstand [, <span
class="type">string $actor ]]] )
此函数是该函数的别名: <span class="methodname">SoapHeader::SoapHeader
SoapHeader::SoapHeader
SoapHeader constructor
说明
SoapHeader::SoapHeader ( <span
class="methodparam">string $namespace
, string
$name [, <span
class="type">mixed $data [, <span
class="methodparam">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 <span
class="classname">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 {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $data ,
string
$name )
SoapParam ( <span
class="methodparam">mixed $data ,
string
$name )
}
SoapParam::__construct
SoapParam constructor
说明
public <span
class="methodname">SoapParam::__construct ( <span
class="methodparam">mixed $data ,
string
$name )
此函数是该函数的别名: <span class="methodname">SoapParam::SoapParam
SoapParam::SoapParam
SoapParam constructor
说明
SoapParam::SoapParam ( <span
class="methodparam">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 {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $data ,
<span
class="type">intnull
$encoding [, <span
class="type">string $typeName =
"" [, <span
class="type">string $typeNamespace =
"" [, <span
class="type">string $nodeName =
"" [, <span
class="type">string $nodeNamespace =
"" ]]]] )
SoapVar ( <span
class="methodparam">mixed $data ,
string
$encoding [, <span
class="type">string $type_name [, <span
class="methodparam">string
$type_namespace [, <span
class="type">string $node_name [, <span
class="methodparam">string
$node_namespace ]]]] )
}
SoapVar::__construct
SoapVar constructor
说明
public <span
class="methodname">SoapVar::__construct ( <span
class="methodparam">mixed $data ,
<span
class="type">intnull
$encoding [, <span
class="type">string $typeName =
"" [, <span
class="type">string $typeNamespace =
"" [, <span
class="type">string $nodeName =
"" [, <span
class="type">string $nodeNamespace =
"" ]]]] )
此函数是该函数的别名: SoapVar::SoapVar
SoapVar::SoapVar
SoapVar constructor
说明
SoapVar::SoapVar ( <span
class="methodparam">mixed $data ,
string
$encoding [, <span
class="type">string $type_name [, <span
class="methodparam">string
$type_namespace [, <span
class="type">string $node_name [, <span
class="methodparam">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