c# - 访问域外的 SelfHosted WCF 服务

标签 c# wcf impersonation

我们的 WCF 服务由域内的 Windows 服务自托管,使用 NetTCP 并进行以下设置。

// Set Binding Security.
netTcpBinding.Security.Mode = SecurityMode.Transport;
netTcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
netTcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

我们现在要求允许域外的人员访问这些服务(只要他们能够提供正确的域凭据)。我们的目标不是通过 IIS 托管服务,只是允许外部人员访问我们的服务。在我的测试中,我能够通过在 WCF 调用期间“模拟”客户端代理凭据来从外部连接到服务。

proxy.ClientCredentials.Windows.ClientCredential.Domain = "MyDomainName";
proxy.ClientCredentials.Windows.ClientCredential.UserName = "MyUserName";
proxy.ClientCredentials.Windows.ClientCredential.Password = "MyPassword";

我的问题是:这是正确的方法吗?有没有更好的办法?任何建议将不胜感激。

最佳答案

如果您需要强制(在代码中,例如凭据弹出窗口或从配置文件中读取)设置凭据,则此路由完全有效。更安全的选择是使用 Windows 凭据缓存。首先,您将其设置为使用缓存:

proxy.ChannelFactory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

接下来,您将在凭据缓存中设置凭据。在 Windows XP/2003 中,该位置位于“存储的用户名和密码”(在控制面板中)下;在 Vista/7/2008 中,该位置位于“用户帐户 > 凭据管理器”(在控制面板中)下。

如前所述,您的方法完全有效 - 缓存更安全。

关于c# - 访问域外的 SelfHosted WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7403518/

相关文章:

c# - 从类继承时编译错误

wcf - 在所有服务方法上使用属性 (IOperationBehavior)

java - 模拟 Hadoop 用户

javascript - 我如何使用 jquery 读取简单的 json 结果以及如何发布新结果

wcf - 使用 WIF/STS 保护 WCF 服务 - 使用所需声明装饰方法?

php - MySqlConnection 打开失败,即使模拟也拒绝访问

windows - 在允许的进程之间传递 Windows 安全 token

C# 泛型协变

c# - 部署套件建议

c# - 创建滚动世界的最佳方法是什么?