4
鉴于以下client.php创建此请求XML:使用PHP SOAP扩展从SOAP请求获取参数名称?
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://soap.dev/" 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:Test>
<RequestId xsi:type="xsd:int">1</RequestId>
<PartnerId xsi:type="xsd:int">99</PartnerId>
</ns1:Test>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如何访问这些参数的名字呢? (RequestId和PartnerId)在server.php内?名称是显然有在有效载荷,但在服务器侧接收到只的值(1至99)
示例代码如下:
client.php
<?php
$client_params = array(
'location' => 'http://soap.dev/server.php',
'uri' => 'http://soap.dev/',
'trace' => 1
);
$client = new SoapClient(null, $client_params);
try {
$res = $client->Test(
new SoapParam(1, 'RequestId'),
new SoapParam(99, 'PartnerId')
);
} catch (Exception $Ex) {
print $Ex->getMessage();
}
var_dump($client->__getLastRequest());
var_dump($client->__getLastResponse());
server.php
class receiver {
public function __call ($name, $params)
{
$args = func_get_args();
// here $params equals to array(1, 99)
// I want the names as well.
return var_export($args, 1);
}
}
$server_options = array('uri' => 'http://soap.dev/');
$server = new SoapServer(null, $server_options);
$server->setClass('receiver');
$server->handle();
请注意,我无法真正改变传入的请求格式。
另外,我知道我可以通过创建一个带有$RequestId
和$PartnerId
参数的测试函数将名称返回给参数。
但我真正想要的是从传入的请求中获取名称/值对。
到目前为止,我唯一的想法是简单地解析XML,这是不对的。