0

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;
Clown 123
  • 13
  • 2
  • 4

2 Answers2

1

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"
    }
};
Popo
  • 2,402
  • 5
  • 33
  • 55
  • HttpTransportSecurity() does not contain a definition for Realm. Im using netcore 2.1 – Clown 123 Dec 07 '18 at 18:26
  • @Clown123 ah, okay, are you using .net core 2.1 to generate your proxy classes for calling the web service? – Popo Dec 07 '18 at 19:14
  • Proxy classes? You mean the one that is generated when you use WCF or something else? – Clown 123 Dec 07 '18 at 19:33
  • @Clown123 yes, if you use svcutil via command line or in the project add service reference, either way it generates the proxy classes and contract used in calling the service. – Popo Dec 07 '18 at 20:15
  • Yes that is what i did. I add the service reference and it created the proxys classes. but it doesn't set the realm by itself and i cant find the way to set it. – Clown 123 Dec 07 '18 at 20:26
  • 1
    @Clown123 did you verify that the credentials you are using are valid for the service, that can also cause the error you are getting. As you indicated .net core 2.1 does not use the realm property so that would not be the issue. Also if the proxy classes were generated in a difference .net framework that could potentially cause this issue as well, but it sounds like you are generating them in a core 2.1 project. – Popo Dec 07 '18 at 20:32
0

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.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22