PHP Soap 非 WSDL 调用:如何传递参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/928169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:21:41  来源:igfitidea点击:

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

phpweb-servicessoap

提问by Dave C

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":

我正在尝试像这样在 PHP (5.2.5) 中进行非 WSDL 调用。我确定我错过了一些简单的东西。此调用有一个参数,一个字符串,称为“时区”:

    $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

感谢您的任何建议-
戴夫

采纳答案by Dave C

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

回答by Norberto Soriano

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

@Dave C 的解决方案对我不起作用。环顾四周,我想出了另一个解决方案:

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

希望这可以帮助某人。

回答by ylebre

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.

它应该给你你预期的结果。

回答by Peter Stuifzand

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

您可以尝试array()在您的参数周围添加另一个调用,如下所示:

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

我不能测试这个,但你可以。