的生活結合保持憑據我有一個使用託管在IIS的WCF服務(使用BasicHTTPBinding
)一個WPF客戶端應用程序。我正嘗試轉移到SSL和基本身份驗證,因爲我們有用戶將在離線電腦上使用該應用。我有一個構建並返回服務對象實例的類(我們將其稱爲ProxyGenerator),並存儲用戶名(字符串)和密碼(securestring)。流程從
爲WCF在我的應用程序
登錄窗口,有文本框,密碼框和登錄按鈕。登錄按鈕創建proxygenerator對象,設置它的用戶名和密碼,並將其傳遞(通過參數線程啓動)到:
主窗口,包含用戶界面做實Work®,並呼籲
ProxyGenerator.GetProxy()
獲得代理使用。
這似乎工作確定,直到我們得到:
3. 的UserControl1(嵌入在主窗口),這需要訪問代理服務器。
這將是應對這種理想的方式,因爲需要脫域的訪問?理想情況下,每個人都可以在域上,我可以通過iis使用Windows身份驗證(因此,只要我需要它們就可以從系統獲取用戶憑據,實際上它現在是如何工作的)。
注:這是目前一個「剛剛得到它現在的工作,後來修復」項目。此外,我在這個服務的東西有點新,所以代理可能是錯誤的詞,或者我可能會在錯誤的上下文中使用它。
public class ProxyGenerator
{
public string username;
public SecureString password;
public string endpoint;
private TestingService.ServiceClient _proxy = null;
public ProxyGenerator(string uname, SecureString pword)
{
username = uname;
password = pword;
endpoint = "insert endpoint here"
}
public TestingService.ServiceClient GetProxy()
{
_proxy = new ServiceClient(endpoint);
_proxy.ClientCredentials.UserName.UserName = username;
_proxy.ClientCredentials.UserName.Password = password;
return _proxy;
}
}