[英]Setting credentials for a WCF application?
我寫了一個簡單的應用程序,利用WCF在客戶端和服務器之間進行通信。 當我在本地運行它工作正常,但是當我在兩個不同的盒子上運行服務器和客戶端時,我得到以下異常:
Unexpected error occured, while getting the group names from the VDN server
System.ServiceModel.Security.SecurityNegotiationException: The server has rejected the client credentials.
System.Security.Authentication.InvalidCredentialException: The server has rejected the client credentials.
System.ComponentModel.Win32Exception: The logon attempt failed
什么是不被接受的憑證? 我該怎么設置它們?
有沒有辦法將服務器配置為不需要身份驗證? 該應用程序是一個簡單的監控應用程序,安全性並不是真正的問題。
很抱歉不是非常具體:該應用程序使用管道代理,並且沒有wcf配置文件,因為wcf代碼是手動編碼的。
我的WCF代碼基於本教程中的代碼: http : //www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication
我沒有知道從配置生成wcf類直到我寫完所有代碼之后才是標准的proctice。 現在每當我查看教程/幫助文檔時,他們都會使用生成的代碼,所有內容都需要更改配置。
我沒有帶寬(我已經在處理3個項目)用一個使用生成的代碼替換我的wcf組件但我確保下次使用wcf時使用代碼生成。
這是我在搜索禁用wcf安全/身份驗證時找到的解決方案。
來自MSDN :
WSHttpBinding b = new WSHttpBinding();
b.Security.Mode = SecurityMode.None;
或者在config中添加以下內容:
<wsHttpBinding>
<binding name="myBinding">
<security mode="None" />
</binding>
</wsHttpBinding>
創建這樣的方法......
void SetImpersonation(ref IServiceClient proxy)
{
proxy.ClientCredentials.Windows.ClientCredential.Domain = "MYDOMAIN";
proxy.ClientCredentials.Windows.ClientCredential.UserName = "A_USER";
proxy.ClientCredentials.Windows.ClientCredential.Password = "P4SSW0RD";
}
並在創建新客戶端類時調用它。
IServiceClient proxy = new IServiceClient ();
SetImpersonation(ref proxy);
顯然,這是將信息設置為特定用戶,如果您的代碼被反編譯,則會產生安全隱患,但它應該適用於您的(無文件配置文件的情況)
如果您使用具有以下安全性的WCF綁定配置:
<transport clientCredentialType="Windows" />
那么您需要在如下代碼中創建的WCF實例上顯式設置Windows憑據:
'Create an instance of the WCF service
Dim MyService As New MyWCFServiceClient
'Build credentials object for which this WCF call will be made
MyService.ClientCredentials.Windows.ClientCredential = New System.Net.NetworkCredential("UserName", "Password", "DomainName")
'Call a method on the service
MyService.MyMethod1()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.