doudongdang4483 2016-03-07 04:43
浏览 51
已采纳

PHP SOAP调用客户端函数

I need call soap client functions without libraries(nusoap , zendframework , laravel) I only should to work with php native because is a requiriment for the another proyect more important on the future so for the moment I just practice with a simple public Web Service from Here( http://www.service-repository.com/operation/show?operation=GetCitiesByCountry&portType=GlobalWeatherSoap&id=4 ) , but I need Help.I try to call client soap functions but I recive this error:

Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Procedure or function 'getWCity' expects parameter '@CountryName', which was not supplied. at WebServicex.GlobalWeather.GetCitiesByCountry(String CountryName) --- End of inner exception stack trace --- in /Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php:41 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php(41): SoapClient->__soapCall('GetCitiesByCoun...', Array) #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/php-soap/soap/Client.php on line 41

This is my server Class:

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();

This is my client class:

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();

Please Help me.

</div>
  • 写回答

1条回答 默认 最新

  • doufu8588 2016-07-19 16:28
    关注

    Following the wsdl provided, I think the right way to call it is

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

    One thing is the GetCitiesByCountry SOAP action, and another is the GetCitiesByCountry element.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算