我正在使用 PHPSoapClient
使用 SOAP 服务,但收到一条错误消息,指出 SOAP 服务无法看到我的参数。
<tns:GenericSearchResponse xmlns:tns="http://.../1.0">
<tns:Status>
<tns:StatusCode>1</tns:StatusCode>
<tns:StatusMessage>Invalid calling system</tns:StatusMessage>
</tns:Status>
</tns:GenericSearchResponse>
PHP 的 SoapClient 发送 XML 以进行 SOAP 调用:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://.../1.0">
<SOAP-ENV:Body>
<ns1:GenericSearchRequest>
<UniqueIdentifier>12345678</UniqueIdentifier>
<CallingSystem>WEB</CallingSystem>
</ns1:GenericSearchRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我最初使用soap-ui,在使用相同的 WSDL 时它可以成功工作。 XMLsoap-ui 发送调用:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://.../1.0">
<SOAP-ENV:Body>
<ns1:GenericSearchRequest>
<ns1:UniqueIdentifier>12345678</ns1:UniqueIdentifier>
<ns1:CallingSystem>WEB</ns1:CallingSystem>
</ns1:GenericSearchRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
区别在于UniqueIdentifier
and CallingSystem
参数前缀为ns1
在soap-ui 请求中。
我尝试过使用传递SoapVar
反对SoapClient
调用,但这不会增加参数标签并为其添加前缀ns1
.
我知道WEB
是一个有效的CallingSystem
XSD 指定的值,并且在使用soap-ui 时有效。
我现在的SoapClient
code:
try {
$client = new SoapClient($wsdl, array('trace' => 1));
$query = new stdClass;
$query->UniqueIdentifier = $id;
$query->CallingSystem = 'WEB';
$response = $client->GenericUniqueIdentifierSearch($query);
} catch (SoapFault $ex) {
$this->view->error = $ex->getMessage();
...
}
I found 这篇博文 http://eosrei.net/articles/2012/01/php-soap-xml-attributes-namespaces-xmlwriter但我希望可能有一个更干净的实施。
Update:
Used a 这个问题的解决方案 https://stackoverflow.com/a/10932943/122075但相当笨重:
$xml = "<ns1:GenericSearchRequest>"
. "<ns1:UniqueIdentifier>$id</ns1:UniqueIdentifier>"
. "<ns1:CallingSystem>WEB</ns1:CallingSystem>"
. "</ns1:GenericSearchRequest>";
$query = new SoapVar($xml, XSD_ANYXML);
$response = $this->client->__SoapCall(
'GenericUniqueIdentifierSearch',
array($query)
);