I'm attempting to get FaultExceptions to hit for a WSDL service.
I have attempted the following:
- Created a new .Net 7.0 project in Visual studio
- Added the WSDL service reference for
https://wsaimport.uni-login.dk/wsaimport-v7/ws?WSDL - Called the generated WSDL method
hentDataAftalerAsync - Added below code to Program.cs
var binding = new CustomBinding(new TextMessageEncodingBindingElement(MessageVersion.CreateVersion(EnvelopeVersion.Soap12, AddressingVersion.None), Encoding.UTF8), new HttpsTransportBindingElement { MaxReceivedMessageSize = 104857600 });
var ws10Client = new ServiceReference2.WsaImportPortTypeClient(binding, new EndpointAddress("https://wsaimport.uni-login.dk/wsaimport-v7/ws"));
try
{
var res = await ws10Client.hentDataAftalerAsync(new Credentials() {
wsBrugerid = "randomusername",
wsPassword = "randompassword"
});
// this is reached if credentials are correct
foreach (var item in res.hentDataAftalerResponse1.ToList())
{
Console.WriteLine(item);
}
}
catch(FaultException<AuthentificationError> ex)
{
// Neven hit (I expect this exception on wrong credentials)
Console.WriteLine(ex.Message);
}
catch (FaultException ex)
{
// Never hit
Console.WriteLine(ex.Message);
}
catch (ProtocolException ex)
{
// this exception is hit (but no info about the actual soap fault)
}
catch (Exception ex)
{
// Never hit
Console.WriteLine(ex.Message);
}
I have tested the hentDataAftaler operation in SoapUI, and when the credentials are wrong it does generate a SOAP response with a Fault of authentificationError.
So my question is, why is it not working for me in C#?