我有我已經在web應用web.config中創造了以下配置WCF服務獲取DefaultNetworkCredentials通過對WCF服務
<service name="RedwebServerManager.WebApplication.DesktopService"
behaviorConfiguration="ServBehave">
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="basicBind"
contract="RedwebServerManager.WebApplication.IDesktopService"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicBind">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
這種服務需要採取WindowsCredentials在一個獲取信息基於認證用戶的數據庫。該服務目前有一個方法實現一個接口具有以下簽名
[ServiceContract]
public interface IDesktopService
{
/// <summary>
/// Gets the clients.
/// </summary>
/// <returns>IEnumerable<ClientServiceModel>.</returns>
[OperationContract]
IEnumerable<ClientServiceModel> GetClients();
}
我有一個Windows窗體應用程序,它在消費WCF服務,我想使用的應用程序,因爲這樣會通過當前用戶的憑據都在我們的領域。在app.config如下
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDesktopService">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://redwebservermanager.redweb.network/DesktopService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDesktopService"
contract="ManagerService.IDesktopService" name="BasicHttpBinding_IDesktopService" />
</client>
</system.serviceModel>
如果我手動設置憑據的用戶名和密碼,一切正常,但是我一直在努力
managerService.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials
,這樣我可以在傳遞當前用戶的憑據,但我在GetClients()調用中不會設置用戶名和密碼的錯誤。
任何人都可以幫助我嗎?我也嘗試加入
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
該方法,但這沒有什麼區別。
我知道這聽起來很愚蠢,但你有沒有嘗試過**並沒有設置** ClientCredential'。我們使用'NetTcpBinding'來保證交通安全以及上述工作。 –