【问题标题】:Pass Windows credentials to remote WCF service将 Windows 凭据传递给远程 WCF 服务
【发布时间】:2015-11-15 14:59:12
【问题描述】:

我有一个远程 WCF 服务,托管在 IIS 上。然后我有一个托管在 Azure 网站上的 ASP.NET MVC 网站。

该网站使用 Azure Active Directory 对用户进行身份验证,并且运行良好。但是,WCF 服务需要正确的 Windows(基于域)凭据才能返回结果。

当我在我的 ASP.NET MVC 应用程序中实例化服务时,我正在使用:

SomeService.ServiceClient client = new ServiceClient ("SOAP");
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

这是由Web.config 文件支持的:

<basicHttpBinding>
  <binding name="SOAP" allowCookies="true" maxReceivedMessageSize="20000000"
           maxBufferSize="20000000"
           maxBufferPoolSize="20000000">
    <readerQuotas maxDepth="32"
           maxArrayLength="200000000"
           maxStringContentLength="200000000"/>

    <security mode="TransportCredentialOnly">
      <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
  </binding>
</basicHttpBinding>

当我在本地运行 时,它运行良好 - 我正在从本地 AppPool 获取凭据,这些凭据可用于访问 WCF 服务。但是,一旦我将网站部署到 Azure,上述情况就会中断,因为服务显然不知道我在本地拥有的凭据。

问题:

有没有办法让我通过浏览器将 Windows 凭据传递给 WCF 服务,而不会破坏 AAD 身份验证堆栈,因为我只需要那些用于 WCF 连接而不需要其他任何东西?我完全可以显示系统提示输入凭据。

【问题讨论】:

  • 你有没有想过这个问题?我正在尝试做同样的事情,但我想使用 .NET 服务客户端从 javascript 而不是 C# 调用所述 Web 服务,就像你正在做的那样。

标签: asp.net asp.net-mvc wcf azure azure-active-directory


【解决方案1】:

您应该能够像这样设置 Windows 凭据...

 SomeService.ServiceClient client = new ServiceClient ("SOAP");
 client.ClientCredentials.Windows.ClientCredential = new NetworkCredential("Username", "Password", "Domain");

希望这会有所帮助!

【讨论】:

  • 这意味着要么对凭据进行硬编码,要么我构建一个自定义提示来传递这些凭据。在我这样做之前,我想知道是否有一种内置的方法可以在没有开销的情况下这样做。谢谢!
  • 不用担心 - 您是否尝试过传递 System.Net.CredentialCache.DefaultCredentials
  • DefaultCredentials 表示当前运行应用程序的安全上下文的系统凭据,因此它将获取服务器上的 AppPool 上下文,而不是我的本地计算机。
猜你喜欢
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 2013-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多