class SoapClient (View source)

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

Methods

SoapClient(string|null $wsdl, array $options = null)

SoapClient constructor

__construct(string|null $wsdl, array $options = [])

SoapClient constructor

mixed
__call(string $name, array $args)

No description

mixed
__soapCall(string $name, array $args, array $options = null, mixed $inputHeaders = null, array $outputHeaders = null)

Calls a SOAP function

string|null
__getLastRequest()

Returns last SOAP request

string|null
__getLastResponse()

Returns last SOAP response

string|null
__getLastRequestHeaders()

Returns the SOAP headers from the last request

string|null
__getLastResponseHeaders()

Returns the SOAP headers from the last response

array|null
__getFunctions()

Returns list of available SOAP functions

array|null
__getTypes()

Returns a list of SOAP types

array
__getCookies()

Returns a list of all cookies

string|null
__doRequest(string $request, string $location, string $action, int $version, bool|int $oneWay = false)

Performs a SOAP request

void
__setCookie(string $name, string $value)

The __setCookie purpose

string|null
__setLocation(string $location = null)

Sets the location of the Web service to use

bool
__setSoapHeaders(mixed $headers = null)

Sets SOAP headers for subsequent calls

Details

SoapClient(string|null $wsdl, array $options = null)

Since: 5.0.1

SoapClient constructor

Parameters

string|null $wsdl

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

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.

array $options

[optional]

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.

__construct(string|null $wsdl, array $options = [])

Since: 5.0.1

SoapClient constructor

Parameters

string|null $wsdl

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

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.

array $options

[optional]

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.

Exceptions

SoapFault

mixed __call(string $name, array $args)

Since: 5.0.1

No description

Parameters

string $name
array $args

Return Value

mixed

mixed __soapCall(string $name, array $args, array $options = null, mixed $inputHeaders = null, array $outputHeaders = null)

Since: 5.0.1

Calls a SOAP function

Parameters

string $name

The name of the SOAP function to call.

array $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.

array $options

[optional]

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.

mixed $inputHeaders

[optional]

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

array $outputHeaders

[optional]

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

Return Value

mixed

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. If this option is not set, or is set to TRUE, then a SoapFault object will be thrown as an exception.

Exceptions

SoapFault

string|null __getLastRequest()

Since: 5.0.1

Returns last SOAP request

Return Value

string|null

The last SOAP request, as an XML string.

string|null __getLastResponse()

Since: 5.0.1

Returns last SOAP response

Return Value

string|null

The last SOAP response, as an XML string.

string|null __getLastRequestHeaders()

Since: 5.0.1

Returns the SOAP headers from the last request

Return Value

string|null

The last SOAP request headers.

string|null __getLastResponseHeaders()

Since: 5.0.1

Returns the SOAP headers from the last response

Return Value

string|null

The last SOAP response headers.

array|null __getFunctions()

Since: 5.0.1

Returns list of available SOAP functions

Return Value

array|null

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

array|null __getTypes()

Since: 5.0.1

Returns a list of SOAP types

Return Value

array|null

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

array __getCookies()

Since: 5.4.3

Returns a list of all cookies

Return Value

array

The array of all cookies

string|null __doRequest(string $request, string $location, string $action, int $version, bool|int $oneWay = false)

Since: 5.0.1

Performs a SOAP request

Parameters

string $request

The XML SOAP request.

string $location

The URL to request.

string $action

The SOAP action.

int $version

The SOAP version.

bool|int $oneWay

[optional]

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

Return Value

string|null

The XML SOAP response.

void __setCookie(string $name, string $value)

Since: 5.0.4

The __setCookie purpose

Parameters

string $name

The name of the cookie.

string $value

[optional]

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

Return Value

void

No value is returned.

string|null __setLocation(string $location = null)

Since: 5.0.1

Sets the location of the Web service to use

Parameters

string $location

[optional]

The new endpoint URL.

Return Value

string|null

The old endpoint URL.

bool __setSoapHeaders(mixed $headers = null)

Since: 5.0.5

Sets SOAP headers for subsequent calls

Parameters

mixed $headers

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.

Return Value

bool

TRUE on success or FALSE on failure.