首页 文章

PHP SOAP调用客户端函数

提问于
浏览
0

我需要调用soap客户端函数而不使用库(nusoap,zendframework,laravel)我只应该使用php native,因为这是对未来更重要的另一个proyect的要求所以目前我只是使用一个简单的公共Web服务来实践这里(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 第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 回答

  • 1

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

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

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

相关问题