Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Soap non-WSDL call: how do you pass parameters?

I'm trying to make a non-WSDL call in PHP (5.2.5) like this. I'm sure I'm missing something simple. This call has one parameter, a string, called "timezone":

    $URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';

    $client = new SoapClient(null, array(
        'location' => $URL,
        'uri'      => "http://www.Nanonull.com/TimeService/",
        'trace'    => 1,
        ));

// First attempt:
// FAILS: SoapFault: Object reference not set to an instance of an object
   $return = $client->__soapCall("getTimeZoneTime",
       array(new SoapParam('ZULU', 'timezone')),
       array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
    );

// Second attempt:
// FAILS: Generated soap Request uses "param0" instead of "timezone"
   $return = $client->__soapCall("getTimeZoneTime",
       array('timezone'=>'ZULU' ),
       array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
   );

Thanks for any suggestions
-Dave

like image 529
Dave C Avatar asked May 29 '09 21:05

Dave C


3 Answers

Thanks. Here's the complete example which now works:

$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';

$client = new SoapClient(null, array(
    'location' => $URL,
    'uri'      => "http://www.Nanonull.com/TimeService/",
    'trace'    => 1,
    ));

$return = $client->__soapCall("getTimeZoneTime",
   array(new SoapParam('ZULU', 'ns1:timezone')),
   array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
like image 152
Dave C Avatar answered Nov 14 '22 09:11

Dave C


@Dave C's solution didn't work for me. Looking around I came up with another solution:

$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';

$client = new SoapClient(null, array(
    'location' => $URL,
    'uri'      => "http://www.Nanonull.com/TimeService/",
    'trace'    => 1,
    ));

$return = $client->__soapCall("getTimeZoneTime",
   array(new SoapParam(new SoapVar('ZULU', XSD_DATETIME), 'timezone')),
   array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);

Hope this can help somebody.

like image 24
Norberto Soriano Avatar answered Nov 14 '22 08:11

Norberto Soriano


The problem lies somewhere in the lack of namespace information in the parameter. I used the first case of your example since it was closest to what I came up with.

If you change the line:

array(new SoapParam('ZULU', 'timezone')),

to:

array(new SoapParam('ZULU', 'ns1:timezone')),

it should give you the result you expected.

like image 5
ylebre Avatar answered Nov 14 '22 09:11

ylebre