是否有任何使用WCF REST服务和桌面客户端的基本HTTP身份验证的示例? 我正在使用WCF REST Contrib。当从浏览器使用javascript客户端时,身份验证工作正常,但是当我尝试使用C#Console应用程序时。我收到 BasicUnauthorizedException {“您未能成功访问安全资源。”}。即使我提供了正确的用户名和密码。
WebHttpBinding binding = new WebHttpBinding();
binding.SendTimeout = TimeSpan.FromSeconds(25);
binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
Uri address = new Uri("http://localhost:3525/wcfrestdemo/students.svc");
WebChannelFactory<ISudentService> factory =
new WebChannelFactory<ISudentService>(binding, address);
factory.Credentials.UserName.UserName = "jon";
factory.Credentials.UserName.Password = "123";
ISudentService proxy = factory.CreateChannel();
var response = proxy.GetStudents(2010, 4, 2); //throws an error.
任何帮助将不胜感激。