Search code examples
javaphparraysweb-serviceswsdl

Exception when trying to send an array via php webservice


When I'm trying to get an array object on the Android client side I get this error:

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) 

I read some of the answers here for that problem and they say its because the parameters like name space or url or soap command were wrong. This is not the case.

I am trying to build a PHP web service using nusoap and calling one of the methods. The method is supposed to return an array:

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;
}

The Person 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;
    }
}

The problem happens when trying to return an array with that person object inside. When I do that, I get on the client side the exception above. If I'm trying to return null, it works without exception. If I'm trying to return the array without pushing the person object inside, I get an empty array without any exception. I tried changing the method to return only an object of type Person not in an array and it also works. Only when trying to return an array with an object inside I get the exception. Do you perhaps see why?


Solution

  • I have found the problem. I used Visual Studio to add the service to a new sln and there I managed to find a way to view the SOAP message that was returned from the web service. It seemed that there was a warning in the nusoap.php file. in the current version it was in line 6132:

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

    This warning was added to the returned SOAP message for some reason and that made the parser not recognize the content of the message. After I commented out the line, the problem was fixed.