PHP SOAP调用客户端函数

时间:2016-03-07 04:43:30

标签: php web-services soap wsdl

我需要调用没有库的肥皂客户端函数(nusoap,zendframework,laravel)我只应该使用php native,因为这是另一个对未来更重要的proyect的要求所以目前我只是简单的公共实践来自Here的Web Service(http://www.service-repository.com/operation/show?operation=GetCitiesByCountry&portType=GlobalWeatherSoap&id=4),但我需要Help.I尝试调用客户端soap函数,但我发现了这个错误:

  

致命错误:未捕获的SoapFault异常:[soap:Server] System.Web.Services.Protocols.SoapException:服务器无法处理请求。 ---> System.Data.SqlClient.SqlException:过程或函数'getWCity'需要参数'@CountryName',这是未提供的。在WebServicex.GlobalWeather.GetCitiesByCountry(String CountryName)---内部异常堆栈跟踪结束---在/Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php:41堆栈跟踪:#0 / Applications /XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php(41):/ Applications / XAMPP / xamppfiles / htdocs中抛出的SoapClient-> __ soapCall('GetCitiesByCoun ...',Array)#1 {main}第41行的/php-soap/soap/Client.php

这是我的服务器类:

class ServerSoap extends SoapServer{
  public function __construct(){
    $params= array('encoding'=>'UTF-8','soap_version' => SOAP_1_2);
$wsdl="http://www.webservicex.com/globalweather.asmx?WSDL";
    parent::SoapServer($wsdl,$params);
    parent::addFunction("GetCitiesByCountry");
  }
      public function fault ($code, $string, $actor = null, $details = null, $name = null) {
          throw new SoapFault($code, $string, $actor, $details, $name);
      }
}
$server = new ServerSoap();
$server->setClass('ServerSoap');
$server->handle();

这是我的客户端类:

class Client extends SoapClient{
  public function __construct(){
$wsdl_client="http://localhost:8080/php-soap/soap/ServerSoap.php?wsdl";
$params_client = array(
  'trace' => TRUE,
  'wsdl'=>TRUE,
  'debug'=>TRUE,
  'cache_wsdl'=>WSDL_CACHE_BOTH
);
  parent::__construct($wsdl_client,$params_client);
  $this->server = new SoapServer($wsdl_client,$params_client);
  }
  public function disableClient(){
    $old_location = $this->instance->__setLocation();
    return $old_location;
  }

}
$country="Spain";
$client = new Client();
$client->__soapCall("GetCitiesByCountry", array("CountryName"=>$country));
echo $client->__getLastResponse();

请帮助我。

1 个答案:

答案 0 :(得分:1)

在提供的wsdl之后,我认为正确的方法是

$client->GetCitiesByCountry([
    'GetCitiesByCountry' => [
        'CountryName' => $country
    ]
];

有一件事是GetCitiesByCountry SOAP动作,另一件是GetCitiesByCountry元素。

相关问题