I have used php.net and followed the documentation for creating a SOAP request using SoapClient in php, but I have not been able to figure out how to get the request formatted correctly with headers in the correct place. This is causing an “invalid autentication type used” error when my script runs.
The example request I need to form is:
<?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>
<ServiceAuthHeader xmlns="http://voicepad.com/DataServices_Vivek/DataServices">
<Username>string</Username>
<Password>string</Password>
</ServiceAuthHeader>
</soap12:Header>
<soap12:Body>
<GetData xmlns="http://voicepad.com/DataServices_Vivek/DataServices">
<sQueryType>string</sQueryType>
<StartDate>string</StartDate>
<EndDate>string</EndDate>
<PhoneNumber>string</PhoneNumber>
</GetData>
</soap12:Body>
</soap12:Envelope>
My last try using php to make the request is:
$client = new SoapClient("url", array( 'trace' => TRUE, 'exceptions'=>0 ));
$header = new SoapHeader( 'soap12', 'ServiceAuthHeader', array('Username' => "$s_uname", 'Password' => "$s_pass"));
$client->__setSoapHeaders(array($header));
$result = $client->GetData(array('PhoneNumber'=>'##########'));
print_r($result);
The request this code is generating is this:
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://voicepad.com/DataServices_Vivek/DataServices" xmlns:ns2="soap12">
<soap-env:header>
<ns2:serviceauthheader>
<item>
<key>
Username
</key>
<value>
*********
</value>
</item>
<item>
<key>
Password
</key>
<value>
*********
</value>
</item>
</ns2:serviceauthheader>
</soap-env:header>
<soap-env:body>
<ns1:getdata>
<ns1:phonenumber>
###########
</ns1:phonenumber>
</ns1:getdata>
</soap-env:body>
</soap-env:envelope>
as you can see this request is wrong, but its also the closes ive been able to get. its the ONLY trial I had where i at least got the username and password to show up in the header of the request. I’m lost somebody please help!
If you are looking at the first comment on the PHP.net documentation for SoapHeader, the example is exactly what you need, besides the fact that you also need to set the XML namespace correctly.
One has to know that XML has several rules to mark elements as belonging to them, and that this does not matter to the XML processor.
So here is the adjusted example for your problem. I hope it works for you: