PHP SOAP help needed

Hello,

Not very experienced with SOAP and recently I bumped into an issue with it.
I have to make certain requests to the SOAP server and just can’t make it work. Is there anyone experienced with SOAP that could put me on the right track? I suspect that the authentication isn’t done properly thus returning me empty data objects.

Here’s a sample of my code (including the WSDL):


$auth = array(
        'AuthHeader' => array('Username' => 'myuser', 'Password' => 'mypass'),
        'trace' => true
    );

try {
    $client = new SoapClient("http://www.eurotaxglasswebservices.com.au/GeneralGGWebService.asmx?WSDL", $auth);
    $result = $client->__soapCall( 'GetListOfYears', array('ModelTypeCode' => 'A') );
    echo $client->__getLastRequest();
} catch (SoapFault $e) {
    var_dump($e);
}

here is how the client request supposed to be:

POST /GeneralGGWebService.asmx HTTP/1.1
Host: www.eurotaxglasswebservices.com.au
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <AuthHeader xmlns="http://microsoft.com/webservices/">
      <Username>string</Username>
      <Password>string</Password>
    </AuthHeader>
  </soap12:Header>
  <soap12:Body>
    <GetListOfYears xmlns="http://microsoft.com/webservices/">
      <ModelTypeCode>string</ModelTypeCode>
    </GetListOfYears>
  </soap12:Body>
</soap12:Envelope>

and here is how mine looks :frowning:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://microsoft.com/webservices/">
<SOAP-ENV:Body>
<ns1:GetListOfYears/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Thank you very much for your time, I would really appreciate any advice you could have for me.

Problem solved. Just in case anyone will bump into the same issue, here’s the solution:

try
{
 	$client = new SoapClient("http://www.your-wsdl-url.asmx?WSDL");
}
catch (Exception $e)
{
	print_r($e);
}

$headerbody["Username"] = 'myusername';
$headerbody["Password"] = 'mypassword';
$ns = "http://microsoft.com/webservices/";

$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);
$client->__setSoapHeaders($header);

Cheers!