Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I catch data from the XML content of a SOAP request in a php SOAPServer?
    text
    copied!<p>I am trying to set up a SOAP service in php. I declared a server php function and I am able to call that function with a SOAP type http request where the content is my SOAP envelope.</p> <p>The XML content of the SOAP body is the argument of the function I assume, but I don't know how to access the information in it in my php code.</p> <p>I noticed that the function argument is an instance of <code>stdClass</code> by default, and I actually wonder why it is not casted on an <code>XML</code> or <code>DOM</code> object by php - it's a SOAP call isn't it? But all right, now it's up to me to get the information out of the object, which is not easy because there's no methods assigned to <code>stdClass</code>, so it'll have to be standard php functions. So I tried <code>serialize</code>, but this gave me some rubbish, not the XML string I expected.</p> <p>What to do?</p> <p><strong>EDIT</strong></p> <p><em>note that below has no example code of what I wish to do - get some detail data from the XML content of the SOAP request - because I don't know how to code getting it from the stdClass object</em></p> <p>On request of david, here's some details.</p> <p>php code:</p> <pre><code>&lt;?php function mi102($arg) { $txt = serialize ($arg); $result = new SoapVar ($txt, XSD_ANYXML); return($result); } ini_set( "soap.wsdl_cache_enabled", "0"); $server = new SoapServer ("test.wsdl"); $server -&gt; addFunction ("mi102"); try { $server -&gt; handle(); } catch (Exception $e) { $server -&gt; fault ('Client', $e -&gt; getMessage()); } ?php&gt; </code></pre> <p>http request is constructed by an application that I use; the http header and the soap envelope + body are generated around the XML I feed it:</p> <p>SOAP request body content:</p> <pre><code>&lt;mi102 xmlns="http://pse"&gt; &lt;cdhead cisprik="21"/&gt; &lt;instr&gt; &lt;insid&gt; &lt;bcdt&gt;20120930&lt;/bcdt&gt; &lt;/insid&gt; &lt;/instr&gt; &lt;/mi102&gt; </code></pre> <p>The WSDL used is as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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/"&gt; &lt;types&gt; &lt;xs:schema&gt; &lt;xs:import namespace="http://pse/" schemaLocation="PSE.xsd"/&gt; &lt;/xs:schema&gt; &lt;/types&gt; &lt;message name="MI102Req"&gt; &lt;part name="cdhead" type="tns:cdhead_T"/&gt; &lt;part name="instr" type="tns:instr_T"/&gt; &lt;/message&gt; &lt;message name="Res"&gt; &lt;part name="cdhead" type="tns:cdhead_T"/&gt; &lt;/message&gt; &lt;portType name="MIPortType"&gt; &lt;operation name="mi102"&gt; &lt;input message="tns:MI102Req"/&gt; &lt;output message="tns:Res"/&gt; &lt;/operation&gt; &lt;/portType&gt; &lt;binding name="MIBinding" type="tns:MIPortType"&gt; &lt;soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/&gt; &lt;operation name="mi102"&gt; &lt;soap:operation soapAction="http://testServerURL/test_soap.php#mi102"/&gt; &lt;input&gt; &lt;soap:body use="literal" namespace="http://pse/"/&gt; &lt;/input&gt; &lt;output&gt; &lt;soap:body use="literal" namespace="http://pse/"/&gt; &lt;/output&gt; &lt;/operation&gt; &lt;/binding&gt; &lt;service name="PSE"&gt; &lt;port name="MIPortType" binding="tns:MIBinding"&gt; &lt;soap:address location="http://testServerURL/test_soap.php"/&gt; &lt;/port&gt; &lt;/service&gt; &lt;/definitions&gt; </code></pre> <p>And the resulting XML (again, extracted from the SOAP body by the application I use), is</p> <p>SOAP response:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;ns1:mi102Response xmlns:ns1="http://pse/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;O:8:"stdClass":2:{s:7:"cisprik";i:21;s:7:"version";s:2:"13";}&lt;/ns1:mi102Response&gt; </code></pre> <p>Not nice.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload