我有一個自我託管的WCF服務,具有簡單的用戶名/密碼驗證。在託管服務conosle應用程序代碼中的「安全」部分是:Windows Phone 8 BasicHttpBinding安全
BasicHttpBinding b = new BasicHttpBinding();
b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
//add endpoint
selfHost.AddServiceEndpoint(typeof(ISettings), b, "SettingsService");
//add creditential check
selfHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
selfHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustomValidator();
但我不能弄清楚如何在我的Windows手機上使用的用戶名/密碼creditentials做的,這是我有這麼遠:
BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
sc = new SettingsClient(httpBinding, new EndpointAddress("http://" + addressField.Text + "/IC/SettingsService"));
sc.ClientCredentials.UserName.UserName = "test";
sc.ClientCredentials.UserName.Password = "test123";
總是返回401錯誤。另外我沒有任何特殊的配置在我的XML文件。
是託管在IIS或IIS Express/WebDev? – Cybermaxs
它是自己託管的。 – Squeazer