使用php和wsdl查询soap以获得结果

时间:2018-02-05 15:39:28

标签: php soap wsdl

我很难找到一个如何在php中使用wsdl进行soap调用的好例子。

我找到了这个例子,但它与谷歌功能有关:

doGoogleSearch

$hits = $soap->doGoogleSearch('your google key',$query,0,10,
                               true,'',false,'lang_en','','');

我为wsdl找到了这个例子,但我没看到我的查询在哪里:

missingQuery

所以基本上,这是我到目前为止所做的,但是有很多缺失:

$wsdlDB = "htmlString?wsdl";
// xml string for login and query I know works in soapUI with $var
    $query = "$query = 
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tri="http://blah/dbOurs/">
   <soapenv:Header/>
   <soapenv:Body>
      <tri:sendTransaction>
        <loginName>unernm</loginName>
         <loginPassword>pw</loginPassword>
                ...
   </soapenv:Body>
</soapenv:Envelope>'

$result = "not sure where this ties in either";

$WSDL = new SOAP_WSDL($wsdlDB);
$soap = $WSDL->getProxy();

$hits = $soap->($query, $result);

//然后我将使用正则表达式从$ result中提取$ varAnswer

这真的不清楚。有没有人有关于如何使用WSDL将查询提交到数据库的任何有用信息?我不应该给soap调用一个特定的函数来进行查询。它应该从wsdl定义中获得。

1 个答案:

答案 0 :(得分:0)

为什么不使用内置的SoapClient。它会将函数的输入转换为Soap消息,并将返回消息提取到对象中;基于WSDL。

简单示例如下所示。

$blzCode = '10010424'; // Code to lookup
$wsdlDB = "http://www.thomas-bayer.com/axis2/services/BLZService?wsdl"; // WSDL URL
$client = new SoapClient($wsdlDB); // Create the client based on the WSDL
$returnValue = $client->GetBank(array('blz' => $blzCode)); // Pass in the Parameters to the call (Based on the WSDL's definition)
$bankDetails = $returnValue->details; // Extract the results
$bankName = $bankDetails->bezeichnung; // Extract some portion of the inner result
echo "Blz Code {$blzCode}'s bank name is {$bankName}" . PHP_EOL; // Do something with the data