<?php
    header
("Content-type: text/html; charset=utf-8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Web service client - setting up a SOAP header</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="Cache-Control" content="no cache" />
        <meta http-equiv="Pragma" content="no_cache" />
        <meta name="author" content="attila szabo (www.w3net.eu)" />
        <meta name="robots" content="noindex, nofollow" />
        <style type="text/css">
        body {
            font-family: verdana;
            background: #ffffff; 
        }
        .xmlBox {
            width: 80%;
            border:1px solid #B2B2B2;
            height: 140px;
            background:#F4F4F4 none repeat scroll 0 0;
            word-spacing:normal;
            padding: 4px;
        }
        .message {
            margin: 1.5em 0;
            padding: 15px;
            font-size: 90%;
            line-height: 1.5em;
            border-left: none;
            border-right: none;
        }
        .error {
            background-color: #FFDDCC;
            border-top: 3px solid #DD0000;
            border-bottom: 3px solid #DD0000;
        }
        div.comment {
            padding-left: 17px; text-align: left; border: 0px;
            background-color: #eee;
            margin-top: 0px;
            padding: 10px;
            font:76%/1.5 "Lucida Grande",Geneva,Verdana,Arial,Helvetica,sans-serif;
        }
        code {
            display: block;
            padding-top: 1em;
            margin-left: 20px;
            font-size: 120%;
        }    
        code.inline {
            text-align:left;
            display:inline;
            margin: 0;
        }
        </style>
    </head>
<body>
<pre>
<?php
    error_reporting
(E_ALL);
    
$xmlns 'urn:ExampleAPI';


    try{

        
$client = new SoapClient('http://w3net.eu/code/soap/soap_header/server/service.wsdl', array(
                                 
'style'    => SOAP_DOCUMENT,
                                 
'use'      => SOAP_LITERAL,
                                 
'encoding' => 'UTF-8',
                                 
'trace'    => 1
                                
));


        
// SOAP Header beállitása
        
class ApiUserAuthHeader {
            public 
$sessionId;
        }

        
$auth = new ApiUserAuthHeader();
        
$auth->sessionId 'ce50f06c3f00a938ddeb78b22bb33c7192932006';

        
/* You MUST encode the object */
        
$authVar = new SoapVar($authSOAP_ENC_OBJECT);
        
$header =  new SoapHeader('urn:ExampleAPI'"ApiUserAuthHeader",$authVarFALSESOAP_ACTOR_NEXT); // !! ignores namespace
        
$client->__setSoapHeaders(array($header));

        
$params = array('apiKey' => 'WorkaholicGroupApiKey',
                        
'sig'    => '0c9ed93ec403851a2f7682aceb98a5a9');
        
$ret $client->__soapCall('login', array($params));


    } catch (
SoapFault $exception) {

        if (
stristr($exception->faultstring,'Couldn\'t load from')){
            die(
"Error: Your computer must be connected to the Internet. Connect to the Internet and try again.");
        }else{
            echo 
'Last Request Headers';
            echo 
"\n<div class='xmlBox'>"htmlspecialchars($client->__getLastRequestHeaders()) ."</div>\n";
            echo 
'Last Request';
            echo 
"\n<textarea class='xmlBox'>"htmlspecialchars($client->__getLastRequest()) ."</textarea>";
            echo 
"\n<div class='msg error'>SOAP client Error: "$exception->faultstring ."</div>\n\n";
        }

    }
?></pre>

<!-- kommentár -->
<p>&nbsp;</p>
<div class="comment" lang="hu">
    A <acronym lang="en" title="Simple Object Access Protocol">SOAP</acronym> kiterjesztés 
    helytelen SOAP XML üzenetet gyártott le a számunkra, 
    mert a <code class="inline">sessionId</code> elem nincsen minősítve 
    névtérelőtaggal (<span lang="en">namespace qualified</span>).
    Mivel nincsen deklarálva alapértelmezett névtér feljebbi elemekben, ezért a <code class="inline">sessionId</code> 
    nem tartozik semmilyen névtérhez sem. Ez azért probléma, mert a 
    <acronym lang="en" title="Simple Object Access Protocol">SOAP</acronym> kiszolgáló a <code class="inline">Header</code> elemben 
    az <span lang="en">urn:ExampleAPI:sessionId</span> elemet keresi, olyan pedig nincsen.
    <br /> 
    Ez valószínűleg bug a <a href="http://php.net/soap">PHP <acronym lang="en" title="Simple Object Access Protocol">SOAP</acronym> kiterjesztésben</a>, 
    bár nem vagyok ebben biztos.
    A problémáról itt olvashatunk többet: 
    <a href="http://bugs.php.net/bug.php?id=40318&edit=1">Bug #40318 SOAP_ENC_OBJECT does not encode object properties with namespace</a>.
    A kódot némiképp módosítani kell, a helyesen működő kód <a href="index.php">itt</a> látható. 
</div>

</body></html>