Switching from NuSoap to PHP5 Soap - you need to run jumpstart

Here is the call I'm trying to make:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <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/">
        <urn:sessionId xmlns:urn="http://www.mywebservice.com/webservices/SoapService">LOGINTOKEN=your instance name</urn:sessionId>
    </urn:SessionHeader>
</soap:Header>
<soap:Body xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <ns2:login xmlns:ns2="http://www.mywebservice.com/webservices/SoapService">
        <wsUser>
            <entityId>0</entityId>
            <password>your password</password>
            <username>your username</username>
        </wsUser>
    </ns2:login>
</soap:Body>

But I'm having trouble finding how to set up custom headers in PHP5 Soap. With nuSoap, I could just put all this into a variable and then use it $client->setHeader($headerVar), but I can't find anything like it in PHP. If I could repeat this call, I could understand the rest. Any help would be appreciated!

Thanks in advance!

Update . I read the tutorial after the tutorial and read the PHP docs, but nothing works. I can do what I want with curl (as well as nuSoap), but I thought that the native PHP5 soap would be simpler and possibly more stable. I think not ...

Update 2 Here is the code I'm trying:

$soapurl = 'http://www.mywebservice.com/webservices/SoapService?wsdl';
$client = new SoapClient($soapurl,array('trace'=>true));
$token = "LOGINTOKEN=your instance name";

$header = new SoapHeader('http://www.mywebservice.com/webservices/SoapService', 'SessionHeader', array('sessionId' => $token));
$client->__setSoapHeaders($header);


$client->login(array("wsUser" => array('entityId'=>'0','username'=>'my username','password'=>'my password')));

And the error I get:

**Fatal error**: Uncaught SoapFault exception: [ns1:InvalidSecurity] An error was discovered processing the <wsse:Security> header in C:\www\soap\index.php:12 Stack trace: #0 C:\www\soap\index.php(12): SoapClient->__call('login', Array) #1 C:\www\soap\index.php(12): SoapClient->login(Array) #2 {main} thrown in C:\www\soap\index.php on line 12

3 , , "sessionId" "" , "".

 *REQUEST*:
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.mywebservice.com/webservices/SoapService">
<SOAP-ENV:Header>
<ns1:SessionHeader><item><key>sessionId</key><value>LOGINTOKEN=my token</value></item>
</ns1:SessionHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body><ns1:login><wsUser><entityId>0</entityId><password>my password</password><username>my username</username></wsUser></ns1:login></SOAP-ENV:Body></SOAP-ENV:Envelope>
+3
1

SoapHeader ? - ?

//Assume $token holds your login token and $client holds the SoapClient object
$header = new SoapHeader('http://www.mywebservice.com/webservices/SoapService', 'SessionHeader', array('sessionId' => $token));
$client->__setSoapHeaders($header);

SoapClient. SoapClient . , . XML , urn. PHP, , , . , xmlns . , node XML, 100%. , , URL- , , XML .

, - SoapClient? , , XML SOAP. , SoapHeader, , , .

+2

Source: https://habr.com/ru/post/1765846/


All Articles