pear soap error in complex types
| From: | Michael Rasmussen | Date: | Mon, 25 Oct 2004 00:49:42 +0000 |
| Subject: | pear soap error in complex types | ||
| Groups: | php.soap | ||
| Request: | Send a blank email to php-soap+get-1634@lists.php.net to get a copy of this message | ||
Hi,
Version: pear soap 0.8 rc3
The error discored is that when pear soap returns complex types, either
array or struct, it inserts an indication of how many elements is included
this way. for example SOAP-ENC:arrayType="Struct[2]"
SOAP-ENC:offset="[0]". This is behauvior is wrong according to
SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/. To
the best of my
knowledge it should have been SOAP-ENC:arrayType="Struct"
SOAP-ENC:offset="[2]" instead. Am I wrong?
Given this code:
<?php
require_once 'SOAP/Server.php';
require_once 'SOAP/Disco.php';
require_once 'DB.php';
class IndexServer {
var $__dispatch_map = array();
var $__typedef = array();
var $DSN = 'mysql://test@localhost/freedb'; var $dbh;
function IndexServer() {
$this->connectDB();
$this->__dispatch_map['search'] =
array(
'in' => array('CD' =>
'{urn:IndexServer}CD'), 'out' =>
array('CD' => '{urn:IndexServer}CD')
);
$this->__typedef['CD'] =
array(
'id' => 'string',
'title' => 'string',
'artist' => 'string',
'genre' => 'string'
);
function connectDB() {
$this->dbh =& DB::connect($this->DSN); if
(DB::isError($this->dbh))
die($this->dbh->getMessage());
}
}
function search($CD) {
$CDinfo = array();
$CDinfo = array_merge($CDinfo,$CD);
if (count($CDinfo) != 4) {
$fault =& new Soap_Fault('Not a valid CD object. Try
usage'); return $fault;
}
else {
$sql = 'select * from albums where '; $error = false;
foreach ($CDinfo as $key => $field) {
if (!is_string($field))
$field = sprintf("%d", $field);
switch ($key) {
case 'id': if (!empty($field)) if (strlen($field)
!= 8) $error = true; break; case 'artist': if
(strlen($field) > 255) $error = true; break; case
'title': if (strlen($field) > 255) $error = true;
break; case 'genre': if (strlen($field) > 50)
$error = true; break; default: $error = true;
}
if (!empty($field))
$sql .= $key."='".$field."' and ";
}
$sql = substr_replace($sql, '', strlen($sql) - 4, -1); if
($error) {
$fault = new Soap_Fault('Bad query string: '.$sql.'.
Try usage'); return $fault;
}
$this->dbh->setFetchMode(DB_FETCHMODE_ASSOC); $res =&
$this->dbh->getAll($sql);
if (DB::isError($res)) {
$fault = new Soap_Fault($res->getMessage().'. Query
['.$sql.']'); return $fault;
}
return $res;
}
}
}
$server = new SOAP_Server();
$webservice = new IndexServer();
$server->addObjectMap($webservice, 'http://localhost#IndexServer'); if
(isset($_SERVER['REQUEST_METHOD']) &&
$_SERVER['REQUEST_METHOD']=='POST') {
$server->service($GLOBALS['HTTP_RAW_POST_DATA']);
}
else {
// Create the DISCO server
$disco = new SOAP_DISCO_Server($server,'IndexServer');
header("Content-type: text/xml");
if (isset($_SERVER['QUERY_STRING']) &&
strcasecmp($_SERVER['QUERY_STRING'],'wsdl') == 0) { echo
$disco->getWSDL();
}
else
echo $disco->getDISCO();
}
exit(0);
?>
Produces this error message from Perl SOAP::Lite
Unspecified namespace for type 'Struct[2]' <?xml version="1.0"
encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns4="http://localhost#IndexServer"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns4:searchResponse>
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="Struct[2]"
SOAP-ENC:offset="[0]"> <item>
<id xsi:type="xsd:string">12345678</id> <title
xsi:type="xsd:string">123</title> <artist
xsi:type="xsd:string">1234</artist> <genre
xsi:type="xsd:string">123</genre></item> <item>
<id xsi:type="xsd:string">87654321</id> <title
xsi:type="xsd:string">bob
is rocking</title> <artist xsi:type="xsd:string">1234</artist> <genre
xsi:type="xsd:string">rock</genre></item></return></ns4:searchResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
at soapIndexClient.pl line 25
--
Hilsen/Regards
Michael Rasmussen
Get my public GnuPG keys:
mir <at> datanom <dot> net
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE501F51C
mir <at> miras <dot> org
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917
--------------------------------------------------------------
Q: Heard about the <ethnic> who couldn't spell?
A: He spent the night in a warehouse.