Welcome Guest, Not a member yet? Register   Sign In
Help with Nusoap and CI -- better SOAP library, or just doing something wrong?
#1

[eluser]parrots[/eluser]
I'm using the Nusoap library found in the wiki, and almost all of it is working except for a complication with the returned data that I was hoping someone would have insight into. I've followed the full example of getting Nusoap working (http://ellislab.com/forums/viewthread/60879/). Specifically an element that I'm returning is coming back oddly -- as an "item" with a type "xsd:" (line 4 in code below) as opposed to the "Entry" type which I have defined in the WSDL as the child of Entries. I assume this is nusoap's fallback when it can't figure out what to do.

Code:
<soap:Body>
<ns1:getEntriesForMeetResponse xmlns:ns1="hc:headCount">
<entries xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType=":[2]">
<item xsi:type="xsd:">
<event xsi:type="xsd:string">100m</event>
<affiliation xsi:type="xsd:string">Test High School</affiliation>
</item>
<item xsi:type="xsd:">
<event xsi:type="xsd:string">200m</event>
<affiliation xsi:type="xsd:string">Test High School</affiliation>
</item>
</entries>
</ns1:getEntriesForMeetResponse>
</soap:Body>

Nusoap is configured as follows in the controller's construct method:
Code:
...
        $this->nusoap_server->wsdl->addComplexType(
            "Entries",
            "complexType",
            "array",
            "sequence",
            "",
            array(
                "entry"=>array("name"=>"entry", "type"=>"hc:Entry", 'maxOccurs' => 'unbounded')
            )
        );
        
        $this->nusoap_server->wsdl->addComplexType(
            "Entry",
            "complexType",
            "array",
            "sequence",
            "",
            array(
                "event"=>array("name"=>"event", "type"=>"xsd:string"),
                "affiliation"=>array("name"=>"affiliation", "type"=>"xsd:string")
            )
        );
        
        $this->nusoap_server->register(
            "getEntriesForMeet",
            array(
                "id" => "xsd:int"
            ),
            array(
                "entries"=>"tns:Entries"
            ),
            "hc:headCount",
            "hc:headCount#getEntriesForMeet",
            "rpc",
            "encoded",
            "Gets all entries for a given meet."
        );

and right now I have the getEntriesForMeet just returning some test data I manually create instead of quering the database:

Code:
$entries = array();
            
$entry = array();
$entry['event'] = '100m';
$entry['affiliation'] = 'Test High School';
                                    
$entry2 = array();
$entry2['event'] = '200m';
$entry2['affiliation'] = 'Test High School';
            
array_push($entries, $entry);
array_push($entries, $entry2);
            
return $entries;

It seems like Nusoap doesn't actually try to bind the data to the schema created by the code in the constructer, but rather just tries to generate the xml structure based on the contents of the array returned. Also of concern is that Entries is of the SOAP-ENC:Array type rather than the Entries type that is defined in the schema.

If I just return a native XML type (say, string), everything looks ok. But as soon as I start trying to return complex types I define things go wrong. Has anyone else had luck getting non-trivial SOAP services running in CI? Is nusoap the best way to go?
#2

[eluser]Leonardo Radoiu[/eluser]
Hello!

I looked carefully through your code and I believe you should set the Entry complex type as a struct not as an array and Entries complex type as an array, like this:

// while 'Entry' is a struct...

$server->wsdl->addComplexType(
"Entry",
"complexType",
"struct",
"all",
"",
array(
"event"=>array("name"=>"event", "type"=>"xsdConfusedtring"),
"affiliation"=>array("name"=>"affiliation", "type"=>"xsdConfusedtring")
)
);

// 'Entries' is an array of structs...

$this->nusoap_server->wsdl->addComplexType(
"Entries",
"complexType",
"array",
"",
"SOAP-ENC:Array",
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'ht:Entry[]')
),
'ht:Entry'
);

See also:

http://ez.no/developer/forum/developer/n...data_types

Good luck!
#3

[eluser]parrots[/eluser]
Thanks so much, certainly puts me much closer to it working. There is only one thing bugging me now -- I'm getting the following returned to me:

Code:
...
<entries xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Entry[2]">
<item xsi:type="tns:Entry">
<event xsi:type="xsd:string">Men's 100m</event>
<person xsi:type="tns:Person">
<firstname xsi:type="xsd:string">Curtis</firstname>
<lastname xsi:type="xsd:string">Herbert</lastname>
</person>
</item>
</entries>
...

It looks ok except does it mater that the element is still an 'item' as opposed to an 'entry'? I would have assumed that should be '<entry type="tns:Entry">' since the Person element is showing up properly like that...

Thanks.
#4

[eluser]Nathan Pitman (Nine Four)[/eluser]
Hi parrots, I wonder is there any chance that you might be able to share the working controller and details of your routes.php set up etc?




Theme © iAndrew 2016 - Forum software by © MyBB