Handling SOAP Headers in PHP

I am creating (in PHP) a SOAP server that has its WSDL configured to receive messages that look like this:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://my.awesome.namespace/">
    <SOAP-ENV:Header>
        <ns1:Header>
            <ns1:APIKey>E4C5BDE0-48DC-543C-1CA3-8E55C63F8E60</ns1:APIKey>
            <ns1:SiteID>111</ns1:SiteID>
        </ns1:Header>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns1:Heartbeat>
            <ns1:Message>Hello world.</ns1:Message>
        </ns1:Heartbeat>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I had no problem getting my SOAPServer to process Heartbeat messages - it $server->addFunction("Heartbeat");works fine. However, I want to be able to process the contents of the shell <ns1:Header>, so I can check the API key and site ID to make sure they are what they should be.

I looked here (and, of course, in another place), but the defendant seems to have missed the point. Does anyone know how I can access the title element for validation? Am I adding a function for the header, like a method in the body? ( $server->addFunction("Header");?)

Thank you very well in advance.

+3
1

! .

SOAP-:

$server = new SoapServer($your_wsdl,$any_options);
$server->setClass($name_of_your_class);
$server->handle($location_of_request_data);

, $name_of_your_class, , $your_wsdl, , , <SOAP-ENV:Header>. <ns1:Header>, Header. , . API , , API , true. , , , SOAPFault.

, , Google.

P.S.: , $server->setClass(), , , WSDL. .

PHP/SOAP - , .

Edit/P.P.S.: - $server->addFunction("Header") - , setClass . - .

+6

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


All Articles