我一直在尝试使用PHP SoapClient从SOAP服务获取数据。 如果我指向http://my-service?WSDL(显然我不能公开正确的那个)远离PHP,在一个名为SOAP UI的知名工具上使用正确的参数我得到了正确的响应。但在PHP中,即使使用正确的参数和东西,我的响应总是会得到NULL。
这是我的代码:
<?php
$client = new SoapClient('http://my-service?WSDL',
array('trace'=>true, 'exceptions'=>true));
$params= ['EBMHeader'=> ['EBMID'=> 'anyvalue'],
'DataArea'=> ['Ip'=> '127.0.0.1', 'RequestId'=> '12345']];
try {
$response= $client->MySoapFunction($params);
var_dump($response); // returns always NULL
echo $client->__getLastResponse(); //Returns a valid XML with the proper data
} catch (Exception $exception) {
echo $exception;
}
我已经尝试过这些:
$client->__soapCall('MySoapFunction', $params, null);
结果是一样的。__getLastResponse()
输出并将其解析为var,这样我们就可以将它转换为数组,但结果是一个空对象: $xml= $client->__getLastResponse();
$response = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA);
这是来自PHP的$client->__getLastRequest()
的XML请求:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/">
<SOAP-ENV:Body>
<ns2:ConsultarProductoABM>
<ns1:EBMHeader>
<ns1:EBMID>whatever</ns1:EBMID>
</ns1:EBMHeader>
<ns2:DataArea>
<ns2:Ip>127.0.0.1</ns2:Ip>
<ns2:RequestId>12345</ns2:RequestId>
</ns2:DataArea>
</ns2:ConsultarProductoABM>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是我的回复$client->__getLastResponse()
:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<v1:ConsultarProductoResponseEBM xmlns:v1="http://url.com/EnterpriseObjects/Core/EBM/Producto/V1/">
<v11:EBMHeader xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/">
<v11:EBMID>anything</v11:EBMID>
<v11:CreationDateTime>2015-10-16T19:09:54.962-03:00</v11:CreationDateTime>
<v11:Sender>ATG</v11:Sender>
<v11:Target>SMFLX</v11:Target>
<v11:BusinessScope>SIN_CONFIGURACION</v11:BusinessScope>
<v11:BusinessScope>SIN_CONFIGURACION</v11:BusinessScope>
<v11:BusinessScope>SIN_CONFIGURACION</v11:BusinessScope>
<v11:BusinessScope>e6e00a83-ce05-4e2a-bdb6-d7bfbd14d84a</v11:BusinessScope>
<v11:EBMTracking>ConsultarProductoAutogestionReqABCS (V1).ConsultarProducto_+++_ConsultarProductoProvisioningProvABCS (V1).ConsultarProducto_+++_ValidarRespuestaEBS (V1).ValidarRespuesta_+++_ConsultarProductoOpenSmartFlexProvABCS (V1).ConsultarProducto_+++_ValidarRespuestaEBS (V1).ValidarRespuesta</v11:EBMTracking>
<v11:FaultNotification>
<ns1:FaultMessage xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"/>
<ns1:FaultingService xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"/>
<ns1:Destination xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"/>
</v11:FaultNotification>
</v11:EBMHeader>
<v11:ReturnCode xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/">0</v11:ReturnCode>
<v11:ReturnMessage xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/"/>
<v11:ErrorCode xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/">0</v11:ErrorCode>
<v1:DataArea>
<v1:InstalledProduct>
<v11:Hub xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">BON</v11:Hub>
<v11:Node xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">BON076A</v11:Node>
<v11:CustomerParty xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">
<v12:Id xmlns:v12="http://url.com/EnterpriseObjects/Core/EBO/CustomerParty/V1/">7889679</v12:Id>
<v12:PartyHuman xmlns:v12="http://url.com/EnterpriseObjects/Core/EBO/CustomerParty/V1/">
<v13:FirstName xmlns:v13="http://url.com/EnterpriseObjects/Core/EBO/Common/V1/">JOHN</v13:FirstName>
<v13:LastName xmlns:v13="http://url.com/EnterpriseObjects/Core/EBO/Common/V1/">DOE</v13:LastName>
</v12:PartyHuman>
<v12:Location xmlns:v12="http://url.com/EnterpriseObjects/Core/EBO/CustomerParty/V1/">
<v13:Address xmlns:v13="http://url.com/EnterpriseObjects/Core/EBO/Common/V1/">
<v13:ProvinceName>LACATION</v13:ProvinceName>
<v13:StateName>LACATION</v13:StateName>
<v13:CityName>LACATION</v13:CityName>
</v13:Address>
</v12:Location>
</v11:CustomerParty>
<v11:ContractID xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">123456</v11:ContractID>
<v11:Service xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">
<v11:ClassId>52</v11:ClassId>
</v11:Service>
</v1:InstalledProduct>
</v1:DataArea>
</v1:ConsultarProductoResponseEBM>
</soap-env:Body>
</soapenv:Envelope>
问题是,如果我这样做,我不知道还能做些什么来获得有效的php响应:
$response= $client->MySoapFunction($params);
var_dump($response);