NuSOAP - 函数参数未正确映射
我正在 PHP 中使用 NuSOAP 编写一个 Web 服务。为了测试它,我编写了服务器和客户端。在服务器端,我像这样注册该函数:
$server->register(
"testFunction",
array("param1" => "xsd:string", "param2" => "xsd:string"),
array("result" => "xsd:string"),
"http://localhost/testApp"
);
在客户端看起来像这样:
require_once("./lib/nusoap.php");
$client = new soapclient("http://localhost/testApp/server.php");
$function = $_GET["function"];
unset($_GET["function"]);
$result = $client->call($function, $_GET);
echo "<pre>". print_r($result, true) ."</pre>";
当我调用它时,
http://localhost/testApp/client.php?function=testFunction¶m1=value1¶m2=value2
它工作正常,但如果我切换 param1 和 param2 并说,
http://localhost/testApp/client.php?function=testFunction¶m2=value2¶m1=value1
然后 param1 获取值 value2
并且 param2 获取值 value1
。显然,它只是按照参数的顺序,而不是名称。
我认为,由于我使用特定的参数名称注册了该函数,然后调用该函数并指定了这些参数名称,因此它们将被相应地分配。
我错过了什么吗?如果参数名称将被丢弃并按您输入的任何顺序分配,那么指定参数名称有何意义?有没有办法让我可以按任何顺序输入参数并让它们正确映射?
I'm writing a web service using NuSOAP in PHP. To test it, I have written both a server and a client. On the server end, I register the function like so:
$server->register(
"testFunction",
array("param1" => "xsd:string", "param2" => "xsd:string"),
array("result" => "xsd:string"),
"http://localhost/testApp"
);
And on the client looks like this:
require_once("./lib/nusoap.php");
$client = new soapclient("http://localhost/testApp/server.php");
$function = $_GET["function"];
unset($_GET["function"]);
$result = $client->call($function, $_GET);
echo "<pre>". print_r($result, true) ."</pre>";
When I call it like
http://localhost/testApp/client.php?function=testFunction¶m1=value1¶m2=value2
it works fine, but if I switch param1 and param2 and say
http://localhost/testApp/client.php?function=testFunction¶m2=value2¶m1=value1
then param1 gets the value value2
and param2 gets the value value1
. So obviously, it just goes by the order of the parameters, not the names.
I figured that since I registered the function with specific parameter names and then called the function, specifying those parameter names, that they would be assigned accordingly.
Am I missing something? What's the point of specifying the parameter names if they will just be thrown out and assigned in whatever order you entered them? Is there a way to make it so that I can enter the parameters in any order and have them map correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许在客户端中使用默认地图:
简单的黑客,即使它并没有“真正”回答您的问题。
请注意,如果您希望客户端了解有关所进行的调用的格式的任何信息,则传递给客户端的 url 必须是 SOAP WSDL。是你的吗? (我已经使用 nuSoap 很长时间了,但我记得只需将“?wsdl”参数添加到服务器 url 就足以让服务器响应有效的 wsdl )
maybe go for a default map in the client:
Simple hack, even though it doesnt "really" answer your questions.
One note, the url you're passing to the client MUST be a SOAP WSDL if you expect the client to know anything about the format of the calls being made. Is yours ? ( It's been a long time I've used nuSoap, but i recall simply adding "?wsdl" param to the server url was enough to have the server respond with a valid wsdl )