【发布时间】:2016-08-24 12:17:07
【问题描述】:
我在 WebApplication 中创建了一个 WCF 服务,在 web.config 中具有以下配置
<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();
}
我有一个正在使用 WCF 服务的 Windows 窗体应用程序,我想通过使用该应用程序的当前用户的凭据,因为这将全部位于我们的域中。 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,以上对我们有用。