我正在尝试连接到可通过HTTPS访问并需要身份验证的服务。
我得到的错误是:
试验方法
测试项目1.unittest1.testreharb2b
引发异常:
System.ServiceModel.Security.MessageSecurityException:
HTTP请求未经授权
客户端身份验证方案
“匿名”。身份验证头
从服务器接收的是“基本”
realm=“应用程序”。---gt;
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();