Kevin Dermody
Kevin Dermody

Reputation: 31

PHP SOAP Function calls returning a fault

Having trouble with a basic PHP/SOAP setup

I'm writing a SOAP client in PHP to talk to an existing SOAP Server. It also uses WS-Security.

I have successfully been able to connect (authenticated) and make a __getFunctions call, which returns an array of available functions using the following code:

<?php

$wsdlPath = "https://xxx.xxx.xxx.xxx/services/Service?wsdl";

$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$token = new stdClass;
$token->Username = new SOAPVar('xUSERx', XSD_STRING, null, null, null, $ns);
$token->Password = new SOAPVar('xPASSx', XSD_STRING, null, null, null, $ns);

$wsec = new stdClass;
$wsec->UsernameToken = new SoapVar($token, SOAP_ENC_OBJECT, null, null, null, $ns);

$headers = new SOAPHeader($ns, 'Security', $wsec, true);

if (!$client)
{
    $client = new SoapClient($wsdlPath);
    echo "Conn:YES";
}
else
{
    echo "Conn:NO";
}

$client->__setSOAPHeaders($headers);

try
{
   print_r($client->__getFunctions());    
}
catch (SoapFault $exception)
{
   print($exception); 
}

?>

Which gives the following output (messy, but you get the idea):

Conn:YES
Array (
    [0] => editChannelResponse editChannel(editChannel $parameters)
    [1] => getDownloadTokenResponse getDownloadToken(getDownloadToken $parameters)
    [2] => startCallResponse startCall(startCall $parameters)
    [3] => getCallsResponse getCalls(getCalls $parameters)
    [4] => endCalendarCallResponse endCalendarCall(endCalendarCall $parameters)
    [5] => createChannelResponse createChannel(createChannel $parameters)
    [6] => getArchivesByCallIdsResponse getArchivesByCallIds(getArchivesByCallIds $parameters)
    [7] => getChannelsResponse getChannels(getChannels $parameters)
    [8] => createVRRResponse createVRR(createVRR $parameters)
    [9] => getTemplateResponse getTemplate(getTemplate $parameters)
    [10] => getTemplatesResponse getTemplates(getTemplates $parameters)
    [11] => getCallsByStatusResponse getCallsByStatus(getCallsByStatus $parameters)
    [12] => getCallResponse getCall(getCall $parameters)
    [13] => startCalendarCallResponse startCalendarCall(startCalendarCall $parameters)
    [14] => deleteChannelResponse deleteChannel(deleteChannel $parameters)
    [15] => editVRRResponse editVRR(editVRR $parameters)
    [16] => deleteVRRResponse deleteVRR(deleteVRR $parameters)
    [17] => getLiveStreamingsResponse getLiveStreamings(getLiveStreamings $parameters)
    [18] => getHashedPasswordResponse getHashedPassword(getHashedPassword $parameters)
    [19] => getVersionResponse getVersion(getVersion $parameters)
    [20] => endCallResponse endCall(endCall $parameters)
    [21] => getVRRsResponse getVRRs(getVRRs $parameters)
    [22] => getNumberOfArchivesResponse getNumberOfArchives(getNumberOfArchives $parameters)
    [23] => getArchivesResponse getArchives(getArchives $parameters)
    [24] => getVRRResponse getVRR(getVRR $parameters)
)

But when I try to call one of the listed functions directly (getVersion), by replacing

print_r($client->__getFunctions());

with

print_r($client->getVersion());

I get the following error

Conn:YES
SoapFault exception: [soap:Server] 
Fault occurred while processing. in /var/data/www/xxx/beta/soap.php:29 
Stack trace: #0 [internal function]: SoapClient->__call('getVersion', Array) #1 
/var/data/www/xxx/beta/soap.php(29): SoapClient->getVersion() #2 {main}

I don't see any useful information in the error message, and the function I'm calling is one of the listed available options, and I believe my syntax is correct.

Upvotes: 3

Views: 3682

Answers (2)

Barry Chapman
Barry Chapman

Reputation: 6780

Can you try 'manually' invoking the call to that function?

$response = $client->__doRequest( $postdata, 'soaplistenerurl', 'getVersion', 1 );

What does that yield?

Upvotes: 1

Julien Balmont
Julien Balmont

Reputation: 59

You can try to init the SoapClient with the option:

$client = new SoapClient($wsdlPath, array("trace" => true, "exceptions" => true));

If exception is

  • true, any error will raise an Exception.
  • false, you'll get a $client object containing a soapFault message.

Upvotes: 0

Related Questions