【发布时间】:2012-04-29 08:25:47
【问题描述】:
我有这个由 SoapUI 从this wsdl 生成的 xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:safetypay:mws:api:messages">
<soapenv:Header/>
<soapenv:Body>
<urn:CommunicationTestRequest>
<urn:ApiKey>?</urn:ApiKey>
<urn:RequestDateTime>?</urn:RequestDateTime>
<urn:Signature>?</urn:Signature>
</urn:CommunicationTestRequest>
</soapenv:Body>
</soapenv:Envelope>
它工作正常,但是当我使用 PHP 客户端 SoapClient 创建它时,它失败了......我发现错误是因为它略有不同,它只是缺少骨灰盒(我不知道这是什么)。 SoapClient 的 xml 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<CommunicationTestRequest>
<RequestDateTime>2012-04-17T23:21:54</RequestDateTime>
<ApiKey>XXXXX</ApiKey>
<Signature>XXXXX</Signature>
</CommunicationTestRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
三个主要区别是: 1)在定义中,SoapClient 生成的代码缺少这个: xmlns:urn="urn:safetypay:mws:api:messages" 2)在SoapUI生成的xml中,我有soapenv,而在SoapClient生成的xml中,它是SOAP-ENV 3) 在 SoapUI 中,我在每个孩子之前都有瓮,SoapClient 没有。
我几乎一整天都在更改配置并从对象向后移动到数组(因为过去它与其他 wsdl 一起使用),而我在互联网上的研究并没有给我任何帮助......所以...... . 谁能知道我的错误是什么?
请求是这样的:
$std = new RequestDateTime();
$std->RequestDateTime = date ( 'Y-m-d\TH:i:s', time () );
$std->ApiKey = SafetyPaySoap::API_KEY_SAND;
$std->Signature = SafetyPaySoap::SIG_KEY_SAND;
$this->_wsdl->CommunicationTest($std);
SoapClient 的配置在哪里
$config = array ();
$config ['exceptions'] = true;
$config ['trace'] = true;
$config ['cache_wsdl'] = WSDL_CACHE_NONE;
$config ['soap_version'] = SOAP_1_1;
parent::SoapClient ( $url . '?wsdl', $config );
编辑: 我能够修复这个错误。我不得不重写 __doRequest 方法。现在看起来像这样:
public function __doRequest($request, $location, $action, $version, $one_way = null) {
$request = str_ireplace("<{$this->_method}Request>", "<{$this->_method}Request xmlns='urn:safetypay:mws:api:messages'>", $request);
return parent::__doRequest ( $request, $location, $action, $version, $one_way );
}
所以,我正在做的是在请求中添加命名空间,然后它会生成这个 xml:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<CommunicationTestRequest xmlns='urn:safetypay:mws:api:messages'>
<ApiKey>XXXX</ApiKey>
<RequestDateTime>2012-04-18T20:22:51</RequestDateTime>
<Signature>XXXXX</Signature>
</CommunicationTestRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
【问题讨论】:
标签: php web-services soap namespaces wsdl