SoapClient::SoapClient
(PHP 5, PHP 7)
SoapClient::SoapClient — SoapClient constructor
Description
public SoapClient::SoapClient ( mixed $wsdl [, array $options ] )
This constructor creates SoapClient objects in WSDL or non-WSDL mode.
Parameters
-
wsdl -
URI of the
WSDLfile ornullif working innon-WSDLmode.Note:
During development, WSDL caching may be disabled by the use of the
soap.wsdl_cache_ttlphp.ini setting otherwise changes made to the WSDL file will have no effect untilsoap.wsdl_cache_ttlis expired. -
options -
An array of options. If working in WSDL mode, this parameter is optional. If working in non-WSDL mode, the
locationandurioptions must be set, wherelocationis the URL of the SOAP server to send the request to, anduriis the target namespace of the SOAP service.The
styleanduseoptions only work in non-WSDL mode. In WSDL mode, they come from the WSDL file.The
soap_versionoption should be one of eitherSOAP_1_1orSOAP_1_2to select SOAP 1.1 or 1.2, respectively. If omitted, 1.1 is used.For HTTP authentication, the
loginandpasswordoptions can be used to supply credentials. For making an HTTP connection through a proxy server, the optionsproxy_host,proxy_port,proxy_loginandproxy_passwordare also available. For HTTPS client certificate authentication uselocal_certandpassphraseoptions. An authentication may be supplied in theauthenticationoption. The authentication method may be eitherSOAP_AUTHENTICATION_BASIC(default) orSOAP_AUTHENTICATION_DIGEST.The
compressionoption allows to use compression of HTTP SOAP requests and responses.The
encodingoption 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
traceoption enables tracing of request so faults can be backtraced. This defaults tofalseThe
classmapoption 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
traceoption enables use of the methods SoapClient->__getLastRequest, SoapClient->__getLastRequestHeaders, SoapClient->__getLastResponse and SoapClient->__getLastResponseHeaders.The
exceptionsoption is a boolean value defining whether soap errors throw exceptions of type SoapFault.The
connection_timeoutoption 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
typemapoption is an array of type mappings. Type mapping is an array with keystype_name,type_ns(namespace URI),from_xml(callback accepting one string parameter) andto_xml(callback accepting one object parameter).The
cache_wsdloption is one ofWSDL_CACHE_NONE,WSDL_CACHE_DISK,WSDL_CACHE_MEMORYorWSDL_CACHE_BOTH.The
user_agentoption specifies string to use inUser-Agentheader.The
stream_contextoption is a resource for context.The
featuresoption is a bitmask ofSOAP_SINGLE_ELEMENT_ARRAYS,SOAP_USE_XSI_ARRAY_TYPE,SOAP_WAIT_ONE_WAY_CALLS.The
keep_aliveoption is a boolean value defining whether to send theConnection: Keep-Aliveheader orConnection: close.The
ssl_methodoption is one ofSOAP_SSL_METHOD_TLS,SOAP_SSL_METHOD_SSLv2,SOAP_SSL_METHOD_SSLv3orSOAP_SSL_METHOD_SSLv23.
Errors/Exceptions
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.
Examples
Example #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")));
?>
© 1997–2020 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/soapclient.soapclient.php