【问题标题】:WCF client with ssl and username/password authentication具有 ssl 和用户名/密码身份验证的 WCF 客户端
【发布时间】:2010-10-14 19:05:44
【问题描述】:

我正在尝试连接到可通过 https 访问并需要身份验证的服务。

我得到的错误是:

测试方法 TestProject1.UnitTest1.TestReharB2B 抛出异常: System.ServiceModel.Security.MessageSecurityException: HTTP 请求未经授权 客户端认证方案 '匿名的'。身份验证标头 从服务器收到的是“基本 领域="应用程序"'。 ---> System.Net.WebException:远程 服务器返回错误:(401) 未经授权..

在我看来,用户名和密码没有发送到服务。我错过了什么?

代码:

EndpointAddress address = new EndpointAddress(
                    new Uri("https://84.52.158.151:8443/JavaStore/services/B2BService"),
                        EndpointIdentity.CreateDnsIdentity("JavaStore"),
                        new AddressHeaderCollection()
                );

BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

var client = new ReharB2BService.B2BServicePortTypeClient(binding, address);

client.ChannelFactory.Credentials.UserName.UserName = "dotNet";
client.ChannelFactory.Credentials.UserName.Password = "dotnetpwd";

client.Open();
client.getAllItems();

【问题讨论】:

    标签: visual-studio wcf authentication ssl


    【解决方案1】:

    您的服务返回错误,因为服务器和客户端之间存在一些错误配置。您的客户端使用带有 UserName 消息凭据的传输安全性。这意味着使用 HTTPS 并且消息包含带有用户名和密码的 SOAP 标头。但是您的服务返回异常,因为它(可能是 IIS)需要使用基本凭据的传输安全性。这意味着 HTTPS 和 HTTP 基本身份验证(HTTP 标头)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-03
      • 2011-04-09
      相关资源
      最近更新 更多