我想連接到服務,這是通過https訪問和需要身份驗證。WCF客戶端與SSL和用戶名/密碼認證
我得到的錯誤是:
Test method TestProject1.UnitTest1.TestReharB2B threw exception: System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="Application"'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized..
在我看來,這樣的用戶名和密碼不會被髮送到服務。我錯過了什麼?
代碼:因爲服務器和客戶端之間的一些錯誤配置
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();