Note that there are some explanatory texts on larger screens.

plurals
  1. POSwitching from NuSoap to PHP5 Soap - need a jumpstart
    text
    copied!<p>Here's the call I'm trying to make:</p> <pre><code>&lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;urn:SessionHeader xmlns:urn="http://www.mywebservice.com/webservices/SoapService" xmlns="http://www.mywebservice.com/webservices/SoapService" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;urn:sessionId xmlns:urn="http://www.mywebservice.com/webservices/SoapService"&gt;LOGINTOKEN=your instance name&lt;/urn:sessionId&gt; &lt;/urn:SessionHeader&gt; &lt;/soap:Header&gt; &lt;soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;ns2:login xmlns:ns2="http://www.mywebservice.com/webservices/SoapService"&gt; &lt;wsUser&gt; &lt;entityId&gt;0&lt;/entityId&gt; &lt;password&gt;your password&lt;/password&gt; &lt;username&gt;your username&lt;/username&gt; &lt;/wsUser&gt; &lt;/ns2:login&gt; &lt;/soap:Body&gt; </code></pre> <p></p> <p>But I'm having trouble finding out how to set up the custom headers in PHP5's Soap. With nuSoap I could just put the whole thing into a variable and then use <code>$client-&gt;setHeader($headerVar)</code> but I can't find anything similar in PHP. If I could replicate this one call, I can figure the rest out. Any help would be appreciated!</p> <p>Thanks in advance!</p> <p><strong>Update</strong>: I've gone through tutorial after tutorial, and read the PHP docs, but nothing seems to work. I can do what I want with curl (as well as nuSoap) but I thought the native PHP5 Soap would be easier and possibly more stable. I guess not...</p> <p><strong>Update 2</strong> Here's the code I'm trying:</p> <pre><code>$soapurl = 'http://www.mywebservice.com/webservices/SoapService?wsdl'; $client = new SoapClient($soapurl,array('trace'=&gt;true)); $token = "LOGINTOKEN=your instance name"; $header = new SoapHeader('http://www.mywebservice.com/webservices/SoapService', 'SessionHeader', array('sessionId' =&gt; $token)); $client-&gt;__setSoapHeaders($header); $client-&gt;login(array("wsUser" =&gt; array('entityId'=&gt;'0','username'=&gt;'my username','password'=&gt;'my password'))); </code></pre> <p>And the error I get: </p> <pre><code>**Fatal error**: Uncaught SoapFault exception: [ns1:InvalidSecurity] An error was discovered processing the &lt;wsse:Security&gt; header in C:\www\soap\index.php:12 Stack trace: #0 C:\www\soap\index.php(12): SoapClient-&gt;__call('login', Array) #1 C:\www\soap\index.php(12): SoapClient-&gt;login(Array) #2 {main} thrown in C:\www\soap\index.php on line 12 </code></pre> <p><strong>Update 3</strong> So it looks like the "sessionId" is being sent as "key" with the token sent as "value". </p> <pre><code> *REQUEST*: &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://www.mywebservice.com/webservices/SoapService"&gt; &lt;SOAP-ENV:Header&gt; &lt;ns1:SessionHeader&gt;&lt;item&gt;&lt;key&gt;sessionId&lt;/key&gt;&lt;value&gt;LOGINTOKEN=my token&lt;/value&gt;&lt;/item&gt; &lt;/ns1:SessionHeader&gt; &lt;/SOAP-ENV:Header&gt; &lt;SOAP-ENV:Body&gt;&lt;ns1:login&gt;&lt;wsUser&gt;&lt;entityId&gt;0&lt;/entityId&gt;&lt;password&gt;my password&lt;/password&gt;&lt;username&gt;my username&lt;/username&gt;&lt;/wsUser&gt;&lt;/ns1:login&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt; </code></pre>
 

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