Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // $client is PHP's SoapClient class
- try {
- $response = $client->SomeSoapRequest();
- }
- catch(SoapFault $e){
- // handle issues returned by the web service
- }
- catch(Exception $e){
- // handle PHP issues with the request
- }
- HTTP
- ----
- Unable to parse URL
- Unknown protocol. Only http and https are allowed.
- SSL support is not available in this build
- Could not connect to host
- Failed Sending HTTP SOAP request
- Failed to create stream??
- Error Fetching http headers
- Error Fetching http body: No Content-Length: connection closed or chunked data
- Redirection limit reached: aborting
- Didn't recieve an xml document
- Unknown Content-Encoding
- Can't uncompress compressed response
- Error build soap request
- VersionMismatch
- ---------------
- Wrong Version
- Client
- ------
- A SOAP 1.2 envelope can contain only Header and Body
- A SOAP Body element cannot have non Namespace qualified attributes
- A SOAP Envelope element cannot have non Namespace qualified attributes
- A SOAP Header element cannot have non Namespace qualified attributes
- Bad Request
- Body must be present in a SOAP envelope
- Can't find response data
- DTD are not supported by SOAP
- encodingStyle cannot be specified on the Body
- encodingStyle cannot be specified on the Envelope
- encodingStyle cannot be specified on the Header
- Error cannot find parameter
- Error could not find "location" property
- Error finding "uri" property
- looks like we got "Body" with several functions call
- looks like we got "Body" without function call
- looks like we got no XML document
- looks like we got XML without "Envelope" element
- Missing parameter
- mustUnderstand value is not boolean
- SoapClient::__doRequest() failed
- SoapClient::__doRequest() returned non string value
- Unknown Data Encoding Style
- Unknown Error
- DataEncodingUnknown
- MustUnderstand
- --------------
- Header not understood
- Server
- ------
- Couldn't find WSDL
- DTD are not supported by SOAP
- Unknown SOAP version
- WSDL generation is not supported yet
- <?php
- ini_set('default_socket_timeout', 10);
- $client = new SoapClient(null,
- array(
- 'location' => "http://localhost/soapserver.php",
- 'uri' => "http://localhost/soapserver.php",
- 'trace' => 1
- )
- );
- try {
- echo $return = $client->__soapCall("add",array(41, 51));
- } catch (SoapFault $e) {
- echo "<pre>SoapFault: ".print_r($e, true)."</pre>n";
- //echo "<pre>faultcode: '".$e->faultcode."'</pre>";
- //echo "<pre>faultstring: '".$e->getMessage()."'</pre>";
- }
- ?>
- <?php
- function add($a, $b) {
- return $a + $b;
- }
- sleep(20);
- $soap = new SoapServer(null, array('uri' => 'http://localhost/soapserver.php'));
- $soap->addFunction("add");
- $soap->handle();
- ?>
- $client = new SoapClient($wsdl, array("connection_timeout"=>10));
- // SET SOCKET TIMEOUT
- if(defined('RESPONSE_TIMEOUT') && RESPONSE_TIMEOUT != '') {
- ini_set('default_socket_timeout', RESPONSE_TIMEOUT);
- }
- class SoapClientWithTimeout extends SoapClient {
- public function __soapCall ($params, ---) {
- $time_start = microtime(true);
- try {
- $result = parent::__soapCall ($params, ---);
- }
- catch (Exception $e) {
- $time_request = (microtime(true)-$time_start);
- if(
- $e->getMessage() == 'Error Fetching http headers' &&
- ini_get('default_socket_timeout') < $time_request
- ) {
- throw new SoapTimeoutException(
- 'Soap request most likly timed out.'.
- ' It took '.$time_request.
- ' and the limit is '.ini_get('default_socket_timeout')
- );
- }
- // E: Not a timeout, let's rethrow the original exception
- throw $e;
- }
- // All good, no exception from the service or PHP
- return $result;
- }
- }
- class SoapTimeoutException extends Exception {}
- $client = new SoapClientWithTimeout();
- try {
- $response = $client->SomeSoapRequest();
- var_dump($response);
- }
- catch(SoapTimeoutException $e){
- echo 'We experienced a timeout! '. $e->getMessage();
- }
- catch(Exception $e) {
- echo 'Exception: '.$e->getMessage();
- }
- ini_set('default_socket_timeout', 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement