Reputation: 97
A company I'm working with offers a SOAP API to automate use of their service.
The API documentation says "API is nearly universally acceptable: SOAP clients are available for PHP, PERL, Python und Java. However, clients have experienced challenges when integrating into C# environments"
When I make SOAP calls from SoapUI, I can successfully authenticate with the API. However, when I link the WSDL file as a Service Reference in C# in Visual Studio, I get a response from the API, but authentication always fails.
The authentication operation takes 3 parameters:
<part name="salt" type="xsd:string"/>
<part name="token" type="xsd:string"/>
<part name="budgetID" type="xsd:string"/>
Where salt
is a random letter or number, token
is a hash of salt
and my password, and budgetID
is a unique identifier for my account.
SoapUI makes the following call and has the exact result I want:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:loginService">
<soapenv:Header/>
<soapenv:Body>
<urn:doLogin soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<salt xsi:type="xsd:string">12</salt>
<token xsi:type="xsd:string">ae4894ac690d70b0a3ebf27763</token>
<budgetID xsi:type="xsd:string">6e080f339657ce5be68059bec9</budgetID>
</urn:doLogin>
</soapenv:Body>
</soapenv:Envelope>
However, when I make a similar call in C# using the linked Service Reference, using code like below, I get a response from the API but it fails to authenticate:
Random rnd = new Random();
int salt = rnd.Next(1, 10000);
string token;
string budgetKey = "XXX";
using(MD5 md5Hash = MD5.Create())
{
token GetMD5Hash(md5Hash, (salt + txtBudgetPassword.Password).ToString());
}
//Instantiate the web services client created by my Service Reference
loginServicePortClient login = new loginServicePortClient();
Console.Write(login.doLogin(salt, token.ToString(), budgetKey));
Is there some known issue with the .NET/C# SOAP client that's keeping the exact same credentials from working in this client? I know it's not an issue with the MD5 hash because the output of that function is what I used to successfully test the call in SoapUI.
I just have a hard time believing that there's no way to consume this API in C#/.NET.
The API documentation is available here.
EDIT: Here are the headers from the SoapUI and C# calls:
SoapUI:
POST /Budget/loginService.php HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:loginService#loginService#doLogin"
Content-Length: 609
Host: api.textbroker.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
C#:
CONNECT api.textbroker.com:443 HTTP/1.1
Host: api.textbroker.com
Connection: Keep-Alive
Upvotes: 1
Views: 1043
Reputation: 84
Hard to say what is happening but I would start by using fiddler to inspect the soap packet on it's way to the API this will show you if it is malformed or if there is another issue.
Upvotes: 1