How populate composite message and return as SoapServer response XML?

vigTeeddala

New Member
I am setting up a SOAP web service, that should return a composite message.
A valid instance of this message would be the following:\[code\]<dl190Response xmlns="http://pse/"> <cdhead cisprik="5563167"/> <mvts> <mvts_S att="a1"> <x>x1</x> <w>w1</w> </mvts_S> <mvts_S> <x>x2</x> <w>w2</w> </mvts_S> </mvts></dl190Response>\[/code\]All this is neatly defined in the wsdl:\[code\]<?xml version="1.0" encoding="UTF-8"?><definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://pse/" xmlns:xs="http://www.w3.org/2001/XMLSchema" name="PSE" targetNamespace="http://pse/"> <types> <xs:schema xmlns="http://pse/" targetNamespace="http://pse/"> <xs:complexType name="cdhead_T"> <xs:attribute name="cisprik" type="xs:long"/> </xs:complexType> <xs:complexType name="mvts_T"> <xs:sequence> <xs:element name="mvts_S" type="mvts_S_T" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="mvts_S_T"> <xs:sequence> <xs:element name="x" type="xs:string"/> <xs:element name="w" type="xs:string"/> </xs:sequence> <xs:attribute name="att" type="xs:string" use="optional"/> </xs:complexType> </xs:schema> </types> <message name="DL190Req"> <part name="cdhead" type="tns:cdhead_T"/> </message> <message name="DL190Res"> <part name="cdhead" type="tns:cdhead_T"/> <part name="mvts" type="tns:mvts_T"/> </message> <portType name="DLPortType"> <operation name="dl190"> <input message="tns:DL190Req"/> <output message="tns:DL190Res"/> </operation> </portType> <binding name="DLBinding" type="tns:DLPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="dl190"> <soap:operation soapAction="http://www.testServer.com/test_soap.php#dl190"/> <input> <soap:body use="literal" namespace="http://pse/"/> </input> <output> <soap:body use="literal" namespace="http://pse/"/> </output> </operation> </binding> <service name="PSE"> <port name="DLPortType" binding="tns:DLBinding"> <soap:address location="http://www.testServer.com/test_soap.php"/> </port> </service></definitions>\[/code\]I have been working on the server side test_soap.php endlessly to get it right, but I don't succeed.Part of what is working properly up to the point of returning the XML is as follows:\[code\]<?php class PSE { function dl190 ($arg) { //I don't need to extract the input data just now mysql_connect('127.0.0.1:3306', 'user', 'password'); mysql_select_db('myDatabase'); $xml = new SimpleXMLElement('<dl190Res/>'); $xml -> addChild('cdhead'); $mvts = $xml -> addChild('mvts'); $rows = mysql_query('select * from trx'); while($data = http://stackoverflow.com/questions/12772307/mysql_fetch_assoc($rows)) { $mvts_S = $mvts -> addChild('mvts_S'); foreach($data as $key => $value) { if ($key == 'att') { $mvts_S -> addAttribute($key, $value);} else {$mvts_S -> addChild($key, $value);} } }; $dom = dom_import_simplexml ($xml) -> ownerDocument; // now respond to the request and return the XML } }; ini_set( "soap.wsdl_cache_enabled", "0"); $server = new SoapServer ("test.wsdl"); $server -> setClass ('PSE'); $server -> setObject (new PSE()); $server -> handle(); ?>\[/code\]I tried virtually everything I could think of to get the response all right, but I did not succeed. I was able to do the same for a message containing just one part earlier (see my most recent question+answer).
But here, with two message parts, I don't succeed.Debug of the $xml contents show that it is exactly what I wish to see returned, after letting the soap server wrap it into Envelope+Body of course.Actually the situation is different from the one with only one message part: there I could create a new SoapVar from the one part as long as I stripped off the XML declaration first, and return that. Here I cannot do the same, because the return value consists of two parts. So I wonder which of the following I should do now:[*]declare a class for the response message and populate and return that[*]perform some magic with SoapVar and/or SoapParam (mind you, I tried a lot of that already)[*]perform some magic with arrays and SoapVar (tried a lot of that too already)[*]somehow (how?) ask the wsdl for help[*]something completely different[*]quit this entire nightmare with SoapServer and create my own http response from scratchI appreciate all help with this, so all ye soap experts, don't hesitate to try to answer this question!
 
Back
Top