I keep getting the same error no matter what I do. Error is "Authentication header missing! Unable to Authenticate!"
Here is the xml generated from my request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="xxxx" xmlns:ns2="xxxx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Header>
<ns2:ApiAuthentication>
<LoginName>xxxx</LoginName>
<Password>xxxx</Password>
<Company>xxx</Company>
</ns2:ApiAuthentication>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetCustomersRequest>
<ns1:CustomerID>123456</ns1:CustomerID>
<ns1:LoginName xsi:nil="true" />
<ns1:FirstName xsi:nil="true" />
<ns1:LastName xsi:nil="true" />
<ns1:Company xsi:nil="true" />
<ns1:Email xsi:nil="true" />
<ns1:Phone xsi:nil="true" />
<ns1:Phone2 xsi:nil="true" />
<ns1:MobilePhone xsi:nil="true" />
<ns1:Fax xsi:nil="true" />
<ns1:MainAddress1 xsi:nil="true" />
<ns1:MainAddress2 xsi:nil="true" />
<ns1:MainAddress3 xsi:nil="true" />
<ns1:MainCity xsi:nil="true" />
<ns1:MainState xsi:nil="true" />
<ns1:MainZip xsi:nil="true" />
<ns1:MainCountry xsi:nil="true" />
<ns1:TaxID xsi:nil="true" />
<ns1:EnrollerID xsi:nil="true" />
<ns1:SponsorID xsi:nil="true" />
<ns1:Field1 xsi:nil="true" />
<ns1:Field2 xsi:nil="true" />
<ns1:Field3 xsi:nil="true" />
<ns1:Field4 xsi:nil="true" />
<ns1:Field5 xsi:nil="true" />
<ns1:Field6 xsi:nil="true" />
<ns1:Field7 xsi:nil="true" />
<ns1:Field8 xsi:nil="true" />
<ns1:Field9 xsi:nil="true" />
<ns1:Field10 xsi:nil="true" />
<ns1:Field11 xsi:nil="true" />
<ns1:Field12 xsi:nil="true" />
<ns1:Field13 xsi:nil="true" />
<ns1:Field14 xsi:nil="true" />
<ns1:Field15 xsi:nil="true" />
<ns1:CreatedDateStart xsi:nil="true" />
<ns1:CreatedDateEnd xsi:nil="true" />
<ns1:GreaterThanCustomerID xsi:nil="true" />
<ns1:GreaterThanModifiedDate xsi:nil="true" />
<ns1:BatchSize xsi:nil="true" />
</ns1:GetCustomersRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here is the response:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Authentication header missing! Unable to Authenticate!</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
And my php code:
$client = new SoapClient("http://mywebservice.asmx?wsdl",
array(
"trace" => 1,
"exceptions" => 0,
"cache_wsdl" => 0)
);
$namespace = 'http://mynamespace.com';
$creds = new stdClass();
$creds->LoginName = "xxxx";
$creds->Password = "xxxx";
$creds->Company = "xxxx";
$headers[] = new SoapHeader($namespace, 'ApiAuthentication', $creds, false);
$client->__setSoapHeaders($headers);
$response = $client->__soapCall("GetCustomers", array("CustomerID" => "123456"));
var_dump($response);
I've been over my code several times and cannot find anything wrong. I've tried multiple variations of code to set credentials, set soap client and soap header, etc.
Same response everytime is "Authentication header missing! Unable to Authenticate!"
Any ideas of things to check. I've been doing dot.net for the last few years and am just getting back into php.
Thanks in advance.
Use cookies instead of headers. If you find yourself doing it with headers, please tell me.
PHP
$client = new SoapClient('http://somesite/someservice.asmx?wsdl');
$client->__setCookie("LoginName", "myname");
$client->__setCookie("Password", "secret");
$client->__setCookie("Company", "999999999");
ASP.NET
string strLoginName = HttpContext.Current.Request.Cookies.Get("LoginName").Value;
string strPassword = HttpContext.Current.Request.Cookies.Get("Password").Value;
string strCompany = HttpContext.Current.Request.Cookies.Get("Company").Value;