I need to connect Bodet KELIO SOAP Service from a C# application. The documentation for connecting the service is here : https://kelio.help.kelio.io/V5.1P5/fr-FR/webservices/index.html
Test queries are OK from SOAP-UI
I tried to generate the code from the connected service in my projet, using the visual studio 2022 wizard from the WSDL located : https://sandbox-ws.kelio.io/open/services/LightEmployeeService?wsdl user is : api-ws password : ws-sandbox
But when I try to consume it with VS
void SalarieTEst()
{
Salaries.LightEmployeeServicePortTypeClient client = new Salaries.LightEmployeeServicePortTypeClient();
client.ClientCredentials.UserName.UserName = "api-ws";
client.ClientCredentials.UserName.Password = "api-sandbox";
var toto = client.exportLightEmployees("", "");
}
I get the following error :
System.ServiceModel.Security.MessageSecurityException : 'La requête HTTP n'est pas autorisée avec un schéma d'authentification client 'Anonymous'. L'en-tête d'authentification reçu du serveur était 'Basic realm="Bodet Realm"'.'
I tried the code generated by SOAPUI instead, I get a security connection error, but, the result seems to be mismatched, every data are null.
At last, I try to simply query with a standard HttpClient:
async Task TestSoap()
{
var url = @"https://sandbox-ws.kelio.io/open/services/LightEmployeeService";
var soapEnveloppe = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ech=""http://echange.service.open.bodet.com"">
<soapenv:Header/>
<soapenv:Body>
<ech:exportLightEmployeesList>
<!--Optional:-->
<ech:exportFilter>
<!--Zero or more repetitions:-->
<ech:AskedPopulation>
<!--Optional:-->
<ech:populationFilter>Kelio Démonstration</ech:populationFilter>
<!--Optional:-->
<ech:groupFilter>Cadres</ech:groupFilter>
<!--Optional:-->
<ech:populationMode>0</ech:populationMode>
</ech:AskedPopulation>
</ech:exportFilter>
</ech:exportLightEmployeesList>
</soapenv:Body>
</soapenv:Envelope>";
string username = "api-ws";
string password = "api-sandbox";
string domain = "Bodet"; // Optional
var AuthToken = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}"));
using (var Client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, url);
Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", AuthToken);
request.Content = new StringContent(soapEnveloppe, Encoding.UTF8, "text/xml");
var response = await Client.PostAsync(url, request.Content);
}
}
But the same http 403 error occurs.
I also tried with HttpClienderhandler and PreAuthenticate, but always get the same result....
Please help :)