简体   繁体   English

带有参数的PHP SOAP客户端调用函数

[英]PHP SOAP client calling function with parameters

I created a SOAP client like so: 我创建了一个SOAP客户端,如下所示:

$client = new SoapClient("file.wsdl");

And then when I want to call an API function 然后当我想调用API函数时

$client->Authenticate("user", "password");

I get the following error: 我收到以下错误:

The formatter threw an exception while trying to deserialize the message: 格式化程序在尝试反序列化消息时抛出异常:

Error in deserializing body of request message for operation 'Authenticate'. 对操作'Authenticate'反序列化请求消息体时出错。 End element 'Body' from namespace ' http://schemas.xmlsoap.org/soap/envelope/ ' expected. 从命名空间' http://schemas.xmlsoap.org/soap/envelope/ '结束元素'Body'。 Found element 'param1' from namespace ''. 从命名空间''找到元素'param1'。

But when I try to pass parameters in an array, it works, but I get the next error: 但是当我尝试在数组中传递参数时,它可以工作,但是我得到了下一个错误:

["errorMessage"]=>
string(35) "ORA-01008: not all variables bound

My question is: How can I pass parameters in PHP to the SOAP client? 我的问题是:如何将PHP中的参数传递给SOAP客户端? Do they have to be in an array? 他们必须在阵列中吗?

you should pass an array for the parameters and give your parameters names (those can be found in the wsdl-file). 你应该为参数传递一个数组并给出你的参数名称(可以在wsdl文件中找到)。 in your case, the result should look like this (assuming the parameter-names should be param1 and param2 on the basis of the error-message): 在你的情况下,结果应该是这样的(假设参数名称应该是基于错误消息的param1param2 ):

$client->Authenticate(array('param1'=>"user", 'param2'=>"password"));
$info = $client->__call("myAction", ['body' => ['param1' => '123', 'param2' => '456']]);

这一切都取决于soap服务器如何定义,参数可以是你喜欢的字符串和数组。你的问题以前不合法,检查wsdl文件或so​​ap服务器。

   $client = new SoapClient("your wsdl file");
   $stock = "NCR";
   $parameters= array("request"=>$stock);
   $values = $client->someMethod($parameters);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM