我想与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