views:

1358

answers:

3

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

A: 

You could try to add another array() call around your params like this:

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

I can't test this, but you could.

Peter Stuifzand
Tried it, but it passes the entire array as param0. So no go.
Dave C
+1  A: 

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.

ylebre
A: 

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')
);
Dave C