客户端身份验证方案“ Basic”对HTTP请求进行了未授权。从服务器收到的身份验证标头为“ Basic realm =“

时间:2018-12-07 14:23:45

标签: web-services wcf wcf-binding wcf-security transport-security

我正在尝试访问需要身份验证的Soap Web服务(HTTP)。我正在使用WCF来使用该服务。我收到错误消息,因为客户端身份验证方案“基本”未授权HTTP请求。从服务器收到的身份验证标头是“ Basic realm =“ weblogic””。

感谢您的帮助,谢谢。

这是我的代码的样子:

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;

2 个答案:

答案 0 :(得分:0)

如果该服务未通过https进行,请尝试添加以下领域:(我不确定它是否是weblogic,只是按照您在错误中发布的内容进行操作)

binding.Security = new BasicHttpSecurity
{
    Mode = BasicHttpSecurityMode.TransportCredentialOnly,
    Transport = new HttpTransportSecurity()
    {
        ClientCredentialType = HttpClientCredentialType.Basic,
        Realm = "weblogic"
    }
};

答案 1 :(得分:0)

在IIS身份验证模块中启用基本身份验证,然后提供用户名/密码。

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!";

请随时让我知道问题是否仍然存在。