且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP SOAP WSDL 模式在方法调用时返回 Null

更新时间:2022-05-15 00:55:26

使用 PHP SOAP 可能会非常令人沮丧,因为您可能遇到的大多数错误都是不明确的,因此难以调试.

PHP SOAP can be very frustrating to work with as most of the errors you may likely encounter are ambiguous and hence, difficult to debug.

在 WSDL 模式下使用 PHP SOAP 时必须注意一些事项.PHP 函数的输入和输出参数必须在 WSDL 文件(在types"标签或message"标签中)和 PHP 代码(作为类定义)中明确定义.

There are a couple of things that must be noted when working with PHP SOAP in WSDL mode. The input and output parameters of your PHP functions must be clearly defined both in the WSDL file (either in the "types" tag or in the "message" tag) and in your PHP code (as class definition).

您的实施中缺少这两个要求.您的调试输出信息 ($client->__getFunctions()) 也指出了错误,因为您会注意到方法 getDwarves() 和 greetUser() 的返回类型"都是无效".这意味着当您调用这些方法中的任何一个时,PHP SOAP 将返回 null (void),即使您的 PHP 函数定义返回一个值.

These two requirements are missing from your implementation. Your debug output information ($client->__getFunctions()), also pointed out the errors as you will notice that the return "type" for method getDwarves() and greetUser() are both "void". This means that PHP SOAP will return null (void) when you call any of these methods even if your PHP function definition returns a value.

有关更多信息,请查看关于 以 WSDL 模式创建 PHP SOAP 服务器

For more info, check out this simple tutorial on Creating PHP SOAP server in WSDL mode