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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11899706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:24:14  来源:igfitidea点击:

PHP SOAP client calling function with parameters

phpsoap

提问by gorgi93

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'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''.

格式化程序在尝试反序列化消息时抛出异常:

反序列化操作“身份验证”的请求消息正文时出错。来自命名空间“ http://schemas.xmlsoap.org/soap/envelope/”的结束元素“Body” 。从命名空间 '' 中找到元素 '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? Do they have to be in an array?

我的问题是:如何将 PHP 中的参数传递给 SOAP 客户端?他们必须在一个数组中吗?

回答by oezi

you should pass an array for the parameters and give your parameters names (those can be found in the wsdl-file). in your case, the result should look like this (assuming the parameter-names should be param1and param2on the basis of the error-message):

您应该为参数传递一个数组并给出您的参数名称(可以在 wsdl 文件中找到这些名称)。在您的情况下,结果应该如下所示(假设参数名称应该是param1并且param2基于错误消息):

$client->Authenticate(array('param1'=>"user", 'param2'=>"password"));

回答by Fran?ois Breton

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

回答by Wenhuang Lin

it all depends on how the soap server defines,parameters can be string and array as you like.your problem is paras not legal previously,check the wsdl file or the soap server.

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

回答by subh

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