我像这样创建了一个 SOAP 客户端:
$client = new SoapClient("file.wsdl");
然后当我想调用 API 函数时
$client->Authenticate("user", "password");
我收到以下错误:
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 ''.
但是当我尝试在数组中传递参数时,它起作用了,但是我得到了下一个错误:
["errorMessage"]=>
string(35) "ORA-01008: not all variables bound
我的问题是:如何将 PHP 中的参数传递给 SOAP 客户端?它们必须在数组中吗?
最佳答案
您应该为参数传递一个数组并给出您的参数名称(可以在 wsdl 文件中找到)。在您的情况下,结果应如下所示(根据错误消息假设参数名称应为 param1
和 param2
):
$client->Authenticate(array('param1'=>"user", 'param2'=>"password"));
关于带参数的 PHP SOAP 客户端调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11899706/