Ciao a tutti
ho dei problemi a "spostare" oggetti tra server e client (entrambi in php) tramite web service.
Il dato che sposto è un'oggetto composto da altri oggetti, il problema è che il risultato lo trovo all'interno di un'oggetto struct invece che all'interno di un'array.
Leggendo qui http://www.php.net/manual/en/book.soap.php#83409 ho visto che viene evidenziato il problema di spostare oggetti contenenti altri array di oggetti, ho provato a implementare l'interfaccia soapable da estendere ma senza ottenere risultati.
questa è la descrizione nel WSDL ed il codice client/server per le parti di interesse, ho usato direttamente il supporto SOAP di php5.
Ovviamente potrei anche cambiare il codice del client per andare a lavorare su Zone->NameServer->Struct invece che Zone->NameServer ma dato che scrivo un webservice vorrei avere un servizio utilizzabile indipendentemente dalla tecnologia client, altrimenti che scriviamo i WS a fare? :-)
Avete idee o vi siete trovati ancora con problemi simili?
codice:
<xsd:element name="Zone">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="Name" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="SOA" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="TTL" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="Serial" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="Refresh" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="Retry" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="Expire" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="Minimum" type="xsd:string" />
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Nameserver" type="xsd:ZoneNS" />
<xsd:element maxOccurs="unbounded" minOccurs="0" name="MX" type="xsd:ZoneMX" />
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Entries" type="xsd:ZoneEntry" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ZoneNS">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="Value" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ZoneMX">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="Priority" type="xsd:int" />
<xsd:element maxOccurs="1" minOccurs="0" name="Value" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ZoneEntry">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="Key" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="Type" type="xsd:string" />
<xsd:element maxOccurs="1" minOccurs="0" name="Value" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
E il codice lato server è una cosa di questo tipo:
Codice PHP:
$result = new Zone();
$result->Name=$ZoneName->ZoneName;
$result->TTL=trim($matches["TTL"][1][0]);
$result->SOA=trim($matches["SOA"][1][0]);
$result->Serial =trim($matches["SOAINFO"][1][1]);
$result->Refresh =trim($matches["SOAINFO"][1][2]);
$result->Retry =trim($matches["SOAINFO"][1][3]);
$result->Expire =trim($matches["SOAINFO"][1][4]);
$result->Minimum =trim($matches["SOAINFO"][1][5]);
$result->Nameserver=array();
$result->MX=array();
$result->Entries=array();
foreach($matches["NS"][3] as $k=>$NS){
$ZoneNS=new ZoneNS();
$ZoneNS->Value=trim($NS);
$result->Nameserver[]=$ZoneNS;
}
foreach($matches["MX"][5] as $k=>$MX){
$ZoneMX=new ZoneMX();
$ZoneMX->Value=trim($MX);
/*
* the priority is in the match with key 4 in the same position
*/
$ZoneMX->Priority=trim($matches["MX"][4][$k]);
$result->MX[]=$ZoneMX;
}
foreach($matches["ENTRY"][1] as $k=>$ENTRY){
$Type =trim($matches["ENTRY"][3][$k]);
$Value =trim($matches["ENTRY"][4][$k]);
if($Type!="SOA"&&$Type!="NS"&&$Type!="MX"){
$ZoneEntry = new ZoneEntry();
$ZoneEntry->Key=$ENTRY;
$ZoneEntry->Type=$Type;
$ZoneEntry->Value=$Value;
$result->Entries[]=$ZoneEntry;
}
}
$GetZoneResponse = new GetZoneResponse();
$GetZoneResponse->Zone=$result;
return $GetZoneResponse;
mentre nel client ho semplicemente:
Codice PHP:
<?php
require_once("../../lib/bind9wsClient.class.php");
$client = new bind9wsClient("http://localhost/progetti/bind9ws/bind9ws.wsdl");
$check_zone=new ZoneName();
$check_zone->ZoneName="foo.com";
$result = $client->GetZone($check_zone);
var_export($result);
?>
e come risultato ottengo:
codice:
GetZoneResponse::__set_state(array(
'Zone' =>
stdClass::__set_state(array(
'Name' => 'foo.com',
'SOA' => 'dns.foo.com. hostmaster@foo.com.',
'TTL' => '3D',
'Serial' => '2008010901 ; serial, todays date + todays serial #',
'Refresh' => '86400 ; refresh, seconds',
'Retry' => '2H ; retry, seconds',
'Expire' => '1W ; expire, seconds',
'Minimum' => '1D',
'Nameserver' =>
stdClass::__set_state(array(
'Struct' =>
array (
0 =>
stdClass::__set_state(array(
'Value' => 'dns.foo.com.',
)),
1 =>
stdClass::__set_state(array(
'Value' => 'dns2.foo.com.',
)),
),
)),
'MX' =>
stdClass::__set_state(array(
'Struct' =>
stdClass::__set_state(array(
'Priority' => '10',
'Value' => 'mail.foo.com.',
)),
)),
'Entries' =>
stdClass::__set_state(array(
'Struct' =>
array (
0 =>
stdClass::__set_state(array(
'Key' => 'www ',
'Type' => 'CNAME',
'Value' => 'www.test.com.',
)),
1 =>
stdClass::__set_state(array(
'Key' => 'webmail ',
'Type' => 'CNAME',
'Value' => 'mail.test.com.',
)),
2 =>
stdClass::__set_state(array(
'Key' => 'webmail2 ',
'Type' => 'CNAME',
'Value' => 'mail.test.com.',
)),
),
)),
)),
))