In my wsdl file I have a user authentication block:
You're passing your request data inside options for SoapClient
instead of as parameters to the soap call.
The code should look like this (assuming the soap call is Authenticate
):
$client = new SoapClient("http://api.example.com/v2/example?wsdl");
$response = $client->Authenticate(Array(
'iId' => 123456,
'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi',
'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds'));
));
And, in any event, you should use try..catch
to prevent exceptions from crashing your code.
try
{
// code here
}
catch(Exception $e)
{
// error handling goes here
die("Error: ". $e->getMessage()."\n");
}
Without the full WSDL specification it's hard to tell where the issue is. But my guess is you're looking at the specs. wrong. Probably those are headers that need to be sent, not actual methods that need to be called.
So try with something like this:
// SOAP client options
$options = array(
'soap_version' => SOAP_1_2,
'trace' => true,
);
// initialise the SOAP client
$apiURL = 'http://api.example.com/v2/example?wsdl';
$namespace = 'http://api.example.com/v2/example?wsdl';
$client = new SoapClient($apiURL, $options);
// the SOAP headers
$headers = array();
$ua = array(
'iId' => 123456,
'sPassword' => 'fhfhfhfhfhfhfh46464dtdts64iyiyi',
'sType' => 'ghfh57477gghdkskdk68585jghhddhdghds',
);
$headers[] = new SoapHeader($namespace, 'UserAuthentication', $ua);
// we could add multiple headers if needed
$client->__setSoapHeaders($headers);
// call the API function
$response = $client->__soapCall("whateverYourTryingToCall", null);