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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化