PHP + WSDL + SOAP - 如何在屏幕上显示Web服务结果

use*_*218 3 php soap web-services

我刚刚开始使用PHP,并且想要了解如何将Web服务结果显示在数组中.

例如,我想将货币代码从以下WSDL打印到数组中

$wsdl="http://www.webservicex.com/CurrencyConvertor.asmx?WSDL
Run Code Online (Sandbox Code Playgroud)

这就是我到目前为止所做的一切,但没有真正发生过:

$proxyhost="proxy.cpit.ac.nz";  
$proxyport = 8080;  

$wsdl="http://www.webservicex.com/CurrencyConvertor.asmx?WSDL";

$client = new SoapClient($wsdl,
  array('proxy_host' => "$proxyhost",'proxy_port' => 8080, 'trace' => 1));

$country=array();
$result = $client->ConversionRate($country);
print_r($result);
Run Code Online (Sandbox Code Playgroud)

Nic*_*tes 9

基本上,这是你的$ country变量.

如果查看ConversionRate Webservice,它会根据需要定义FromCurrency和ToCurrency.

  <s:element name="ConversionRate"> 
    <s:complexType> 
      <s:sequence> 
        <s:element minOccurs="1" maxOccurs="1" name="FromCurrency" type="tns:Currency" /> 
        <s:element minOccurs="1" maxOccurs="1" name="ToCurrency" type="tns:Currency" /> 
      </s:sequence> 
    </s:complexType> 
  </s:element> 
Run Code Online (Sandbox Code Playgroud)

您需要像这样更新$ country:

$country = array( "FromCurrency" => "AFA",
                  "ToCurrency" => "AUD");
Run Code Online (Sandbox Code Playgroud)

这应该工作.