PHP5 SOAP 请求 - 不发送关联数组参数
我在 php 上编写此脚本来执行 SOAP 请求:
<?php
try {
$soapCli = new SoapClient('somewsdl', array('trace' => 1));
print_r(
$soapCli->__soapCall(
"getUserByCf", array("xxx" => 'ok', "cf" => 'notok')
)
);
echo "REQUEST HEAD:\n" . $soapCli->__getLastRequestHeaders() . "\n";
echo "REQUEST:\n" . $soapCli->__getLastRequest() . "\n";
unset($soapCli);
} catch (SoapFault $e) {
print_r($e);
}
?>
但在我的 wsdl 上,第一个参数是 cf (而不是 xxx)。所以,服务器respost XML是:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getUserByCf>
<cf xsi:type="xsd:string">ok</cf>
<xxx xsi:type="xsd:string">notok</xxx>
</ns1:getUserByCf>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
2个参数被切换。
为什么,如果 _soapCall()
上的参数是
“传递给函数的参数数组。这可以是有序数组,也可以是关联数组。”
我做了一个关联数组,请求不是不关联的吗?
为什么soapCall不关联2个参数,而是切换并在WSDL上的1°名称处关联1°参数,在2°处关联2°参数?
i write this script on php for do a SOAP request:
<?php
try {
$soapCli = new SoapClient('somewsdl', array('trace' => 1));
print_r(
$soapCli->__soapCall(
"getUserByCf", array("xxx" => 'ok', "cf" => 'notok')
)
);
echo "REQUEST HEAD:\n" . $soapCli->__getLastRequestHeaders() . "\n";
echo "REQUEST:\n" . $soapCli->__getLastRequest() . "\n";
unset($soapCli);
} catch (SoapFault $e) {
print_r($e);
}
?>
But on my wsdl first parameter are cf (and not xxx). So, server respost XML is:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:getUserByCf>
<cf xsi:type="xsd:string">ok</cf>
<xxx xsi:type="xsd:string">notok</xxx>
</ns1:getUserByCf>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
2 parameter are switched.
Why, if parameter on _soapCall()
are
"An array of the arguments to pass to the function. This can be either an ordered or an associative array."
And I do an associative array, the request are not not associative?
Why soapCall not associate 2 parameter but Switch and associate 1° parameter at 1° name on WSDL and 2° at 2°?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用参数的关联数组。这意味着您正在使用命名参数。命名参数没有任何顺序,它们有一个名称。顺序并不重要。
如果您想使用未命名参数,可以通过不使用关联数组而仅使用从零开始的数字索引来实现:
请注意,这通常不起作用,因为许多服务需要命名参数。
You are using an associative array for the parameters. That means you are using named parameters. Named parameters don't have any order, they have a name. The order is not important.
If you want to use unnamed parameters, you can do this by not using an associative array but just using numerical indexes, zero-based:
Please take note that this most often does not work because many services require named parameters.