Note that there are some explanatory texts on larger screens.

plurals
  1. POsoap:Envelope SOAP-ENV:Envelope PHP
    text
    copied!<p>I'm trying to login to an API using built-in soap functions of PHP. I got a result like this.</p> <pre><code>[LoginResult]=&gt; false, [ErrorMsg] =&gt; Login failed with the reason : The security object is invalid </code></pre> <p>This is what required by the API provider.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;soap:Body&gt; &lt;Login xmlns="http://tempuri.org/Example/Service1"&gt; &lt;objSecurity&gt; &lt;WebProviderLoginId&gt;test&lt;/WebProviderLoginId&gt; &lt;WebProviderPassword&gt;test&lt;/WebProviderPassword&gt; &lt;IsAgent&gt;false&lt;/IsAgent&gt; &lt;/objSecurity&gt; &lt;OutPut /&gt; &lt;ErrorMsg /&gt; &lt;/Login&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p>&amp;, here is what I was able to produce using functions.</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/Example/Service1"&gt; &lt;SOAP-ENV:Body&gt; &lt;ns1:Login&gt; &lt;objSecurity&gt; &lt;WebProviderLoginId&gt;test&lt;/WebProviderLoginId&gt; &lt;WebProviderPassword&gt;test&lt;/WebProviderPassword&gt; &lt;IsAgent&gt;false&lt;/IsAgent&gt; &lt;/objSecurity&gt; &lt;OutPut/&gt; &lt;ErrorMsg/&gt; &lt;/ns1:Login&gt; &lt;/SOAP-ENV:Body&gt; &lt;/SOAP-ENV:Envelope&gt; </code></pre> <p>Here is the code I used to send the request.</p> <pre><code>&lt;?php class objSecurity { function objSecurity($s, $i, $f) { $this-&gt;WebProviderLoginId = $s; $this-&gt;WebProviderPassword = $i; $this-&gt;IsAgent = $f; } } class nextObject { function nextObject($objSecurity) { $this-&gt;objSecurity=$pobjSecurity; $this-&gt;OutPut=NULL; $this-&gt;ErrorMsg=NULL; } } $url = 'http://example.com/sampleapi/test.asmx?WSDL'; $client = new SoapClient($url, array("soap_version" =&gt; SOAP_1_1,"trace" =&gt; 1)); $struct = new objSecurity('test', 'test', false); $data = new nextObject($struct); $soapstruct2 = new SoapVar($data, SOAP_ENC_OBJECT); print_r( $client-&gt;__soapCall( "Login", array(new SoapParam($soapstruct2, "inputStruct")) ) ); echo $client-&gt;__getLastRequest(); ?&gt; </code></pre> <p>These are the differences I found.</p> <p>In my request <code>xmlns:xsi</code> is missing.</p> <p>Requirement starts with <code>&lt;soap:Envelope</code>, But my request starts with <code>&lt;SOAP-ENV:Envelope</code>.</p> <p>There is an extra <code>xmlns:ns1</code> in my request.</p> <p>&amp; The function name tag starts with <code>ns1:</code>.</p> <p>Please help me to make my request into the required format.</p> <p>I don't know much about the SOAP and I'm using PHP version 5.3.13 with CakePHP 2.3.0. Sorry, for my bad English.</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