【问题标题】:how to call a soap webservice with struct input parameters?如何使用结构输入参数调用soap webservice?
【发布时间】:2016-06-05 12:26:25
【问题描述】:

我想与 SOAP(作为客户端)进行交互,但无法获得正确的输入参数语法。我有一个 WSDL URL,我已经用 SoapUI 对其进行了测试,它正确地返回了结果。 WSDL 中定义了两个函数,但我只需要一个(下面的“FirstFunction”)。这是我为获取可用函数和类型信息而运行的脚本:

$client = new SoapClient("http://example.com/webservices?wsdl");
var_dump($client->__getFunctions()); 
var_dump($client->__getTypes()); 

这是它生成的输出:

array(
  [0] => "FirstFunction Function1(FirstFunction $parameters)",
  [1] => "SecondFunction Function2(SecondFunction $parameters)",
);

struct Amount {
 anyURI Identifier;
 Information charge;
 string referenceCode;
}

struct Information {
 string description;
 decimal amount;
 string code;
}

根据上述结果,我使用nusoap 和php 开发了我的客户端,如下所示:

 class Information 
  {
    public $description;
    public $amount;
    public $code;
  }

  class Amount {

        public $Identifier;
        public $charge;
        public $referenceCode;
  }
$charge = new Information();
$charge->description = "ROUTE=XXX|abc=".$code;
$charge->amount = "NULL";
$charge->code = $chargecode;

$params = new Amount();
$params->Identifier =$num;
$params->charge = $charge;
$params->referenceCode = $refcode;

$header = new SoapHeader('key', $key);

$client->__setSoapHeaders($header);


try
    {
        $res = $client->__call('charge',array('parametrs'=>$params)); 

        print_r($res->return);
    }
catch(PDOException $e)
    {
    print_r($e->getMessage());
    }

我得到以下错误结果:

Uncaught SoapFault exception: [soapenv:Server] unknown

【问题讨论】:

    标签: php soap struct wsdl nusoap


    【解决方案1】:

    在我看来,实现它的最佳方法是使用 WSDL 到 php 生成器,例如 PackageGenerator 项目。它将整个过程抽象化,因此您只需处理对象而不必真正担心 SOAP。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多