I am trying to consume a SOAP Service with a .NET 6 client. The service uses Basic Authentication. I am getting error:
The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm="Custom realm"'.
My code is - to create the binding:
private HttpBindingBase CreateHttpsBinding()
{
var binding = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
binding.Security.Mode = BasicHttpsSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
binding.MessageEncoding = WSMessageEncoding.Mtom;
binding.TransferMode = System.ServiceModel.TransferMode.Buffered;
binding.MaxBufferSize = int.MaxValue;
binding.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
binding.MaxReceivedMessageSize = int.MaxValue;
return binding;
}
And creating the client:
var binding = CreateHttpsBinding();
using (var wsClient = new ExternalService(binding, new EndpointAddress(url)))
{
wsClient.ClientCredentials.UserName.UserName = param.Username;
wsClient.ClientCredentials.UserName.Password = param.Password;
await wsClient.OpenAsync();
var response= await wsClient.SomeCall(input);
The error is given as an Exception on wsClient.SomeCall();
CodePudding user response:
It seems that the error was given because of username/password details!
Initially it was worrying as in .NET Core there is no way to set Realm in Binding Security configuration. But this didn't seem to be a problem.