如何使用PHP SoapClient添加任意命名空间?命名空间实际上并未在请求中使用,但我认为这会阻止我的消息被正确使用。
WSDL在这里:http://abr.business.gov.au/abrxmlsearchRPC/ABRXMLSearch.asmx?WSDL
我要发送的特定邮件的文档位于:http://abr.business.gov.au/abrxmlsearchRPC/(nye2ok45xc42vy552b15dx3t)/FormGenerator/ABRSearchByNameSimpleProtocol.aspx。我在做SOAP请求。
在soap:Envelope中,你会注意到一个名为xmlns:types =“http://abr.business.gov.au/ABRXMLSearchRPC/encodedTypes”的命名空间,你也会注意到它没有在soap中使用:身体
我发送的消息是:(为了安全起见,添加了换行符和缩进,为安全性进行了混淆的authenticationGuid)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://abr.business.gov.au/ABRXMLSearchRPC/" 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:ABRSearchByNameSimpleProtocol>
<name xsi:type="xsd:string">company</name>
<postcode xsi:type="xsd:string"></postcode>
<legalName xsi:type="xsd:string">Y</legalName>
<tradingName xsi:type="xsd:string">Y</tradingName>
<NSW xsi:type="xsd:string">Y</NSW>
<SA xsi:type="xsd:string">Y</SA>
<ACT xsi:type="xsd:string">Y</ACT>
<VIC xsi:type="xsd:string">Y</VIC>
<WA xsi:type="xsd:string">Y</WA>
<NT xsi:type="xsd:string">Y</NT>
<QLD xsi:type="xsd:string">Y</QLD>
<TAS xsi:type="xsd:string">Y</TAS>
<authenticationGuid xsi:type="xsd:string">aaaa</authenticationGuid>
</ns1:ABRSearchByNameSimpleProtocol>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我得到的回应是:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://abr.business.gov.au/ABRXMLSearchRPC/" xmlns:types="http://abr.business.gov.au/ABRXMLSearchRPC/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<types:ABRSearchByNameSimpleProtocolResponse><ABRSearchByNameSimpleProtocolResult href="#id1" /></types:ABRSearchByNameSimpleProtocolResponse>
<types:Payload id="id1" xsi:type="types:Payload">
<Request href="#id2" />
<Response href="#id3" />
</types:Payload>
<types:ExternalRequest id="id2" xsi:type="types:ExternalRequest">
<ExternalRequestBody href="#id4" />
</types:ExternalRequest>
<types:Response id="id3" xsi:type="types:Response">
<DateRegisterLastUpdated xsi:type="xsd:dateTime">0001-01-01T00:00:00.0000000+11:00</DateRegisterLastUpdated>
<DateTimeRetrieved xsi:type="xsd:dateTime">2011-05-26T09:31:06.2949724+10:00</DateTimeRetrieved>
<ResponseBody href="#id5" />
</types:Response>
<types:ExternalRequestNameSearch id="id4" xsi:type="types:ExternalRequestNameSearch">
<AuthenticationGUID xsi:type="xsd:string" />
<Name xsi:type="xsd:string" />
<Filters href="#id6" />
</types:ExternalRequestNameSearch>
<types:ResponseException id="id5" xsi:type="types:ResponseException">
<ExceptionDescription xsi:type="xsd:string">The GUID entered is not recognised as a Registered Party.
Search GUID: </ExceptionDescription>
<ExceptionCode xsi:type="xsd:string">WebServices</ExceptionCode>
</types:ResponseException>
<types:ExternalRequestFilters id="id6" xsi:type="types:ExternalRequestFilters">
<NameType href="#id7" />
<Postcode xsi:type="xsd:string" />
<StateCode href="#id8" />
</types:ExternalRequestFilters>
<types:ExternalRequestFilterNameType id="id7" xsi:type="types:ExternalRequestFilterNameType">
<TradingName xsi:type="xsd:string">Y</TradingName>
<LegalName xsi:type="xsd:string">Y</LegalName>
</types:ExternalRequestFilterNameType>
<types:ExternalRequestFilterStateCode id="id8" xsi:type="types:ExternalRequestFilterStateCode">
<QLD xsi:type="xsd:string">Y</QLD>
<NT xsi:type="xsd:string">Y</NT>
<SA xsi:type="xsd:string">Y</SA>
<WA xsi:type="xsd:string">Y</WA>
<VIC xsi:type="xsd:string">Y</VIC>
<ACT xsi:type="xsd:string">Y</ACT>
<TAS xsi:type="xsd:string">Y</TAS>
<NSW xsi:type="xsd:string">Y</NSW>
</types:ExternalRequestFilterStateCode>
</soap:Body>
</soap:Envelope>
消费者看起来完全忽略了消息的内容。我能看到的唯一缺少的是示例中的类型命名空间,它包含在响应中。
因此,我想如果我可以随意地将类型命名空间添加到请求中,那么它可能会有更好的运气。
如果有人可以告诉我该怎么做,或者提供一些其他建议,为什么消费者会忽略我在请求中给出的价值,那将非常感激。
更新:扩展SoapClient并覆盖__doRequest()以添加命名空间实际上可能是解决方案,但我想要一个知道更好的人的确认。应该注意的是,SoapClient :: getLastRequest()的内容是在__doRequest()进行修改之前生成的,因此可能需要通过tcp转储来观察通过__doRequest()进行的任何修改。
示例代码是
class ABRSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version) {
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->preserveWhiteSpace = false;
$dom->loadXML($request);
$dom->documentElement->setAttribute
('xmlns:types', 'http://abr.business.gov.au/ABRXMLSearchRPC/encodedTypes');
$request = $dom->saveXML();
error_log('Request in class:'.$request);
return parent::__doRequest($request, $location, $action, $version);
}
}