使用 php、soap、wsdl 使用 Web 服务期间出现数组到字符串转换错误

array to string conversion error during consuming a web service using php,soap,wsdl

我正在使用 Nusoap 工具包在 php、soap 和 wsdl 中尝试一个简单的 Web 服务。求和函数已在 server.php 处正确注册并且已创建 Web 服务,但是,要使用 client.php 使用该服务,它会显示以下错误消息:

Notice: Array to string conversion in C:\wamp\www\my\client.php on line 6. Thank you for sharing your experience.

service.php

<?php

function sum($number1,$number2)    
{       
   $result= $number1+$number2;    
    return $result;    
}

?>

client.php

<?php

require('lib/nusoap.php');

        $client=new nusoap_client("http://localhost/my/server.php?wsdl");

$value1=200;

$value2=300;
  $result=$client->call('sum',array('number1'=>"$value1",'number2'=>"$value2"));

echo $result;

?>

首先,它是一个通知,因此不会 "hinder" 执行,所以它可能有效,但如果输出通知是一个问题 you can turn that off

error_reporting(E_ERROR);

其次,通知的来源可能来自$result是一个数组,echo需要一个字符串,或者你的"call"可能需要一个字符串作为第二个范围。你给我们看的是第6行吗?

编辑:如果你只想回显结果,你需要查看结果数组:

print_r($result);

并据此确定结果在数组中的位置,例如;

echo $result['sum'];

或者只查看创建数组的内容以了解其结构