尝试通过 php 网络服务发送数组时出现异常

Exception when trying to send an array via php webservice

当我尝试在 Android 客户端上获取数组对象时,出现此错误:

org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG (empty) <br>@1:7 in java.io.InputStreamReader@415f48e0) 

我在这里阅读了一些关于该问题的答案,他们说这是因为名称 space 或 url 或 soap 命令等参数是错误的。事实并非如此。

我正在尝试使用 nusoap 构建一个 PHP 网络服务并调用其中一种方法。该方法应该 return 一个数组:

function GetAllWorkerUsers($id,$Password)
{
     $ret_array=array();
     $person=new Person( 12, 11, 11, "First", "Last", true, "12345", 0);
     array_push($ret_array, $person->GetWsdlObj()); 
     return $ret_array;
}

这个人 class:

class WorkerUser
{
    public $id;
    public $id2;
    public $id3;
    public $name1;
    public $name2;
    public $somebool;
    public $name3;
    public $id4;


    function __construct($id, $id2, $id3, $name1, $name2, $somebool, $name3, $id4) 
    {
        $this->id = $id;
        $this->id2= $id2;
        $this->id3= $id3;
        $this->name1= $name1;
        $this->name2= $name2;
        $this->somebool= $somebool;
        $this->name3= $name3;
         $this->id4= $id4;
    }

    function GetWsdlObj()
    {
        $obj['id']= $this->id;
        $obj['id2']=$this->id2;
        $obj['id3']=$this->id3;
        $obj['name1']=$this->name1;
        $obj['name2']= $this->name2;
        $obj['somebool']=$this->somebool;
        $obj['name3']=$this->name3;
        $obj['id4']=$this->id4;
        return $obj;
    }
}

尝试 return 一个包含该人物对象的数组时会出现问题。当我这样做时,我在客户端得到了上面的异常。 如果我试图 return null,它会毫无例外地工作。如果我试图 return 数组而不将 person 对象推入其中,我将毫无例外地得到一个空数组。我尝试将方法更改为 return 只有 Person 类型的对象不在数组中并且它也有效。只有在尝试 return 一个内部有对象的数组时,我才会得到异常。你知道为什么吗?

我找到问题了。我使用 Visual Studio 将服务添加到新的 sln,然后我设法找到一种方法来查看从 Web 服务返回的 SOAP 消息。 nusoap.php 文件中似乎有警告。在当前版本中,它位于第 6132 行:

$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");

出于某种原因将此警告添加到返回的 SOAP 消息中,这使得解析器无法识别消息的内容。在我注释掉该行后,问题就解决了。