Reputation: 13
I am trying to access a Soap webservice (HTTP) which requires authentication.I am using WCF to consume the service. I am getting error Message as The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm="weblogic"'.
Any help is appreciated, thank you.
This is what my code looks like:
var binding = new BasicHttpBinding();
binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
binding.Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.TransportCredentialOnly,
Transport = new HttpTransportSecurity()
{
ClientCredentialType = HttpClientCredentialType.Basic
}
};
var endpoint = new System.ServiceModel.EndpointAddress(configuration["webserviceAddres"]);
servicio = new ConsultaMontosOperadosFondosClient(binding, endpoint);
servicio.ClientCredentials.UserName.Password = MyPass;
servicio.ClientCredentials.UserName.UserName = MyUser;
Upvotes: 0
Views: 3986
Reputation: 7522
Enable the basic authentication in IIS authentication module, and then provide the username/password.
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient(binding, new EndpointAddress("http://10.157.13.69:8001/webservice1.asmx"));
client.ClientCredentials.UserName.UserName = "administrator";
client.ClientCredentials.UserName.Password = "abcd1234!";
Feel free to let me know if the problem still exists.
Upvotes: 0
Reputation: 2460
If the service is not over https, then try adding the realm: (I am not sure it is weblogic or not, just going by what you posted in your error)
binding.Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.TransportCredentialOnly,
Transport = new HttpTransportSecurity()
{
ClientCredentialType = HttpClientCredentialType.Basic,
Realm = "weblogic"
}
};
Upvotes: 1