Question

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

Was it helpful?

Solution 2

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

OTHER TIPS

@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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top