0

I have no experience using SOAP/WSDL services before, so the problem might be obvious, but the code (posted below) all result in:

Server was unable to process request. ---> Empty user name and password not allowed. Authentication failed

As far as i understand, it recognises that I invoked the Login method, but it didn't receive my login data.

This is from the API:

Login

Request:

UserName [String]

Password [String]

Response:

SessionId [String] (Description: Session id to use with further API calls)

I see in many SOAP examples that SoapHeader is used for authentication, but it requires a NAMESPACE, and I have no idea what that would be (API doesn't mention any namespace).

My code:

$username    = "blabla";
$password    = "bloblo";

$wsdl         = "https://bla.bla/bla.asmx?wsdl";
$client     = new SoapClient($wsdl, array("trace" => 1, "exception" => 0));

$loginParameters = array("UserName" => $username, "Password" => $password);

//$session = $client->Login->SessionId;
//$session = $client->__soapCall("Login", $loginParameters);
$session = $client->Login($loginParameters);

From WSDL:

<s:schema elementFormDefault="qualified" targetNamespace="http://xxxx/external/api/">
<s:element name="Login">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="userName" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="LoginResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="LoginResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
JamesB
  • 187
  • 3
  • 19
  • I don't have access to the WSDL code... I only have the API. If that makes any sense :o – JamesB May 20 '14 at 10:51
  • Ah, thanks, i didn't even think to just load the URL, thought it wouldn't output anything. Updated post with some info - i guess i have my namespace there as well :) – JamesB May 20 '14 at 11:14

2 Answers2

2

According to the WSDL, your input parameter is called userName not UserName (lowercase u). Also password is all lowercase. So change to:

$loginParameters = array("userName" => $username, "password" => $password);

When retrieving the result, the service returns a response object containing the result. So you would need to do:

$response = $client->Login($loginParameters);
$session = $response->LoginResult;
MrCode
  • 63,975
  • 10
  • 90
  • 112
  • In other words, the problem was that the documentation is wrong... Can't believe how they messed up that! (this is commercial service!) Thanks a lot! Works now! – JamesB May 20 '14 at 21:24
0

This reference may prove useful for the header setup, and this answer may give you more hints about soap namespaces.

Community
  • 1
  • 1
Aboca
  • 575
  • 2
  • 9