无法解析 SOAP 响应



首先,我正在学习使用php中的SoapClient调用Soap Web服务。 我发现自己陷入了在非常复杂的 XML SOAP 响应中获取价值的困境,我需要从中提取值。 我也参考了这个论坛中的一些方法,但不明白。 以下是我收到的回复:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:CleanseUnicodeResponse xmlns:ns="http://soap.web.tsi.trillium.com">
<ns:return xsi:type="ax21:TrilliumRecord" xmlns:ax21="http://quality.tsi.trillium.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax21:numberFields>4</ax21:numberFields>
<ax21:trilliumFieldValues xsi:type="ax21:TrilliumFieldValue">
<ax21:trilliumField>CLEANSE_NAME</ax21:trilliumField>
<ax21:trilliumValue>Fiery Ass</ax21:trilliumValue>
</ax21:trilliumFieldValues>
<ax21:trilliumFieldValues xsi:type="ax21:TrilliumFieldValue">
<ax21:trilliumField>CLEANSE_ID</ax21:trilliumField>
<ax21:trilliumValue>880909999999</ax21:trilliumValue>
</ax21:trilliumFieldValues>
<ax21:trilliumFieldValues xsi:type="ax21:TrilliumFieldValue">
<ax21:trilliumField>CLEANSE_GENDER</ax21:trilliumField>
<ax21:trilliumValue>M</ax21:trilliumValue>
</ax21:trilliumFieldValues>
<ax21:trilliumFieldValues xsi:type="ax21:TrilliumFieldValue">
<ax21:trilliumField>CLEANSE_DOB</ax21:trilliumField>
<ax21:trilliumValue>090988</ax21:trilliumValue>
</ax21:trilliumFieldValues>
<ax21:userKey xsi:nil="true"/>
</ns:return>
</ns:CleanseUnicodeResponse>
</soapenv:Body>
</soapenv:Envelope>

这里是我为检索值而开发的代码。 我似乎无法将其正确转储到数组中。 它不断变为空或空体。

try{
$name = "fiery ass";
$ic = "880909-99-9999";
$gender = "male";
$dob = "12122019";
$webkey = 'U4GBXJZ5';
$url = 'http://192.168.4.147:8484/TrilliumSOAP/services/TrilliumSOAP?wsdl'; 
$soapclient = new SoapClient(null, array(
'location' => $url,
'uri'      => $url,
'trace'    => 1,
));

$xml_post_string = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="0" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">urn:CleanseUnicode</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CleanseUnicode xmlns="http://soap.web.tsi.trillium.com">
<webKey>' . $webkey . '</webKey>
<projectName>TSS DEMO</projectName>
<inputRecord>
<trilliumFieldValues xmlns="http://quality.tsi.trillium.com/xsd">
<trilliumField>SHAREHOLDER_NAME</trilliumField>
<trilliumValue>' . $name . '</trilliumValue>
</trilliumFieldValues>
<trilliumFieldValues xmlns="http://quality.tsi.trillium.com/xsd">
<trilliumField>SHAREHOLDER_ID</trilliumField>
<trilliumValue>' . $ic . '</trilliumValue>
</trilliumFieldValues>
<trilliumFieldValues xmlns="http://quality.tsi.trillium.com/xsd">
<trilliumField>GENDER</trilliumField>
<trilliumValue>' . $gender . '</trilliumValue>
</trilliumFieldValues>
<trilliumFieldValues xmlns="http://quality.tsi.trillium.com/xsd">
<trilliumField>DOB</trilliumField>
<trilliumValue>' . $dob . '</trilliumValue>
</trilliumFieldValues>
<userKey xsi:nil="true" xmlns="http://quality.tsi.trillium.com/xsd" />
</inputRecord>
<outputFields>CLEANSE_NAME</outputFields>
<outputFields>CLEANSE_ID</outputFields>
<outputFields>CLEANSE_GENDER</outputFields>
<outputFields>CLEANSE_DOB</outputFields>
</CleanseUnicode>
</s:Body>
</s:Envelope>'; 

$response = $soapclient->__doRequest($xml_post_string,$url,$url,0); 
$xml = new SimpleXMLElement($response);
$xml->registerXPathNamespace('soapenv', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('ns', 'http://soap.web.tsi.trillium.com');
$xml->registerXPathNamespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->registerXPathNamespace('xml', 'http://www.w3.org/XML/1998/namespace');
$xml->registerXPathNamespace('ax21', 'http://quality.tsi.trillium.com/xsd');
$xpath = '/soapenv:Envelope/soapenv:Body/ns:CleanseUnicodeResponse/text()';
$result = $xml->xpath($xpath);
var_dump($result);

}catch(Exception $e){
echo $e->getMessage();
}

我解析错了吗?还是我错过了什么?我真的迷失在这里。

试试这个

$url = 'http://192.168.4.147:8484/TrilliumSOAP/services/TrilliumSOAP?wsdl'; 
$trace = true;
$exceptions = true;
$token = 9999999;
$soap_version='SOAP_1_2';
$connection_timeout=180;
$name = "fiery ass";

$params=array( 
"ic"= >"880909-99-9999",
"gender" = >"male",
"dob" => "12122019",
"webkey "=> 'U4GBXJZ5'
);
try
{
$client = new SoapClient($url, array('features' => SOAP_SINGLE_ELEMENT_ARRAYS,'soap_version'=>$soap_version,  'trace' => $trace, 'exceptions' => $exceptions,'connection_timeout'=>$connection_timeout));
$response = $client->TrilliumRecord($params);
$feedback= $response->TrilliumRecordResult; 
// var_dump($feedback);  
}
catch (Exception $e)
{
//catch an error
}

}

相关内容

  • 没有找到相关文章

最新更新