[XML] [SOAP] [PHP5] Développement d'un webservice : comment renvoyer du XML ?
Bonjour à tous :D
J'ai déjà développé un webservice soap basique en PHP5, en ce sens que ma fonction retourne un objet simple de type xsd:string.
Maintenant j'ai besoin de retourner des données étendues, sous forme XML. Je m'étais naïvement dit que le xml étant du texte, je pouvais le faire contenir dans un type xsd:string... Hé bien non : PHP fait automatiquement un htmlentities() sur le code xml, résultat, ma requête soap est inexploitable :(
Mon WSDL (fait à la main puisque PHP ne propose aucune génération automatique :evil:) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| <?xml version="1.0" encoding="iso-8859-1" ?>
<!-- partie 1 : Definitions -->
<definitions name="toto"
targetNamespace="urn:toto"
xmlns:typens="urn:toto"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<!-- partie 2 : Types -->
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:toto">
</xsd:schema>
</types>
<!-- partie 3 : Message -->
<message name="getBCCInfoRequest">
<part name="ref" type="xsd:string" />
</message>
<message name="getBCCInfoResponse">
<part name="return" type="xsd:string" />
</message>
<!-- partie 4 : Port Type -->
<portType name="totoPort">
<!-- partie 5 : Operation -->
<operation name="getBCCInfo">
<input message="typens:getBCCInfoRequest"/>
<output message="typens:getBCCInfoResponse"/>
</operation>
</portType>
<!-- partie 6 : Binding -->
<binding name="totoBinding" type="typens:totoPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getBCCInfo">
<soap:operation soapAction="totoAction"/>
<input name="getBCCInfoRequest">
<soap:body use="encoded"
namespace="urn:toto"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output name="getBCCInfoResponse">
<soap:body use="literal" />
</output>
</operation>
</binding>
<!-- partie 7 : Service -->
<service name="totoService">
<documentation>toto Intranet WebService. Contact webmaster for more information.</documentation>
<!-- partie 8 : Port -->
<port name="totoPort" binding="typens:totoBinding">
<soap:address location="http://dev.toto.be/soap/webservice.php"/>
</port>
</service>
</definitions> |
Le code de mon serveur soap, simpliste, pour test :
Code:
1 2 3 4 5 6 7 8 9 10 11
| ini_set("soap.wsdl_cache_enabled", "0");
$srvsoap = new SoapServer('webservice.wsdl');
$srvsoap->addFunction('getBCCInfo');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$srvsoap->handle();
}
function getBCCInfo($ref) {
$xmltxt = '<commande><ref>'.$ref.'</ref><acompte>123.45</acompte></commande>';
return $xmltxt;
} |
Le retour SOAP :
Code:
1 2
| <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:getBCCInfoResponse><return><commande><ref>ttata</ref><acompte>123.45</acompte></commande></return></SOAP-ENV:getBCCInfoResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> |
Sans ces < et > tout fonctionnerait merveilleusement bien...
Comment faire ? Probablement en modifiant le WSDL, mais je ne vois pas comment, j'ai essayé de plein de manière différente, en faisant un type personnalisé, j'ai précisé que le soap:body ne devait pas être encodé (use="literal"), j'ai tenté de passer un objet SimpleXMLElement à la place d'un texte, mais rien n'y fait...
:merci: pour toute aide :)