The class

(No version information available, might only be in SVN)

Introdução

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

Sinopse da classe

SoapClient {
/* Methods */
public mixed ( string $function_name , string $arguments )
( $wsdl [, array $options ] )
public string ( string $request , string $location , string $action , int $version [, int $one_way = 0 ] )
public array ( void )
public string ( void )
public string ( void )
public string ( void )
public string ( void )
public array ( void )
public void ( string $name [, string $value ] )
public string ([ string $new_location ] )
public bool ([ $soapheaders ] )
public mixed ( string $function_name , array $arguments [, array $options [, $input_headers [, array &$output_headers ]]] )
( $wsdl [, array $options ] )
}

Índice

User Contributed Notes

stepan dot zarubin at gmail dot com
Well, this example works fine:

<?php
try { 
   
$x = @new SoapClient("non-existent.wsdl"); 
} catch (
Exception $e) { 
    echo
$e->getMessage();
}
?>

Just make sure use NEW with @.
tlk
Make sure to prefix constructor calls with @ and catch SoapFault exceptions, otherwise you risk having the php interpreter exit/die on simple network issues.

Robust sample code by Rasmus from

<?php 
try { 
   
$x = @new SoapClient("non-existent.wsdl",array("exceptions" => 1)); 
} catch (
SoapFault $E) { 
    echo
$E->faultstring;

echo
"ok\n";
?>
jjlopez
If you are making soap calls in WSDL mode , and the address of your web service includes a port different from 80 (like ), the WSDL file is fetched correctly, but all subsequent requests are made without any port in the host field. This causes a SoapFault exception when trying to call any of the service's methods.

You need to redefine the soapClient class and force the port in each call.

See this example:

hugues at zonereseau dot com
When you need to connect to services requiring to send extra header use this method.

Here how we can to it with PHP and SoapClient

<?php
class exampleChannelAdvisorAuth
{
    public
$DeveloperKey;
    public
$Password;

    public function
__construct($key, $pass)
    {
       
$this->DeveloperKey = $key;
       
$this->Password = $pass;
    }
}

$devKey        = "";
$password    = "";
$accountId    = "";

// Create the SoapClient instance
$url         = "";
$client     = new SoapClient($url, array("trace" => 1, "exception" => 0));

// Create the header
$auth         = new ChannelAdvisorAuth($devKey, $password);
$header     = new SoapHeader("", "APICredentials", $auth, false);

// Call wsdl function
$result = $client->__soapCall("DeleteMarketplaceAd", array(
   
"DeleteMarketplaceAd" => array(
       
"accountID"        => $accountId,
       
"marketplaceAdID"    => "9938745"        // The ads ID
   
)
),
NULL, $header);

// Echo the result
echo "<pre>".print_r($result, true)."</pre>";
if(
$result->DeleteMarketplaceAdResult->Status == "Success")
{
    echo
"Item deleted!";
}
?>
jeffmixpute
Simple php client and server:

Client:

<?php

// bind SOAP/Client.php -> path of the php file
require_once "SOAP/Client.php";

// URI delivered to web service
$sc = new SOAP_Client("");

// start call function to use the function of the Web Service
$parameter = array();
$result = $sc->call ("now", &$parameter, "urn:TimeSerivce");

// print result
print $result."\n";

?>

Server:

<?php

// bind PEAR::SOAP
require_once "SOAP/Server.php";
$skiptrace =& PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
$skiptrace = true;

// program service class
class TimeSerivce {
    public function
now () {
       
       
date_default_timezone_set("Europe/Berlin");
        return (
date ("H:i"));
    }
}

// web service classs develop
$service = new TimeSerivce();

// server develop
$ss = new SOAP_SERVER();

// assing the name to the service
$ss->addObjectMap($service, "urn:TimeSerivce");

// Einstellung, dass POST-Daten an den Service weiter gegeben werden
// preferene to forword POST data to the service
$ss->service ($HTTP_RAW_POST_DATA);

?>
fourat dot zouari at tritux dot com
In addition to the KeepAlive trick which is a "server-side" modification, on the "client side" default_socket_timeout should be increased from its default value (60) when you deal with ~slow SOAP servers.
As for the KeepAlive, if creating a new separate vhost for the soap api is not possible, you can add this to your existing vhost: BrowserMatch "^PHP-SOAP" nokeepalive
where PHP-SOAP is the agent name of your soap client, if you dont know what agent name your client use, just checkout the access.log of your apache.
peter dot hansen at fastit dot net
When you get errors like:
"Fatal error: Uncaught SoapFault exception: [HTTP] Error Fetching http headers in"
after a few (time intensive) SOAP-Calls, check your webserver-config.

Sometimes the webservers "KeepAlive"-Setting tends to result in this error. For SOAP-Environments I recommend you to disable KeepAlive.

Hint: It might be tricky to create a dedicated vhost for your SOAP-Gateways and disable keepalive just for this vhost because for normal webpages Keepalive is a nice speed-boost.