【问题标题】:How to pass credentials from one web service to another?如何将凭据从一个 Web 服务传递到另一个?
【发布时间】:2012-02-19 00:18:56
【问题描述】:

我目前有一个调用 Web 服务 (WS1) 的应用程序,该服务又调用另一个 Web 服务 (WS2) 来获取/设置托管在 WS2 上的服务器上的信息。我希望能够将用户凭据从 WS1 传递到 WS2,就好像有一个应用程序直接调用 WS2 一样。有没有办法做到这一点?

这是我目前拥有的:

申请代码:

BasicHttpBinding basicHttpBinding = 
    new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

basicHttpBinding.Security.Transport.ClientCredentialType = 
    HttpClientCredentialType.Windows;

basicHttpBinding.MaxReceivedMessageSize = 131072000;

AppMgr.AppMgrSoapClient appMgr = 
    new AppMgr.AppMgrSoapClient(
        basicHttpBinding, 
        new EndpointAddress(@"http://SomeServer/Service.asmx"));

appMgr.ClientCredentials.Windows.AllowedImpersonationLevel =
    TokenImpersonationLevel.Impersonation;

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

appMgr.SomeWebMethodCall();

Web 服务 1 代码(在“SomeServer”上)

BasicHttpBinding basicHttpBinding = 
    new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);

basicHttpBinding.Security.Transport.ClientCredentialType = 
    HttpClientCredentialType.Windows;

basicHttpBinding.MaxReceivedMessageSize = 131072000;

WS2Service.WS2ServiceSoapClient myServiceReference = 
    new WS2Service.WS2ServiceSoapClient(
        basicHttpBinding,
        new EndpointAddress(@"http://SomeOtherServer/AnotherService.asmx"));

myServiceReference.ClientCredentials.Windows.AllowedImpersonationLevel = 
    TokenImpersonationLevel.Impersonation;

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

这是我需要更改的 Web 服务代码中的最后一行,我知道...但我不知道将其设置为什么... 有 ClientCredentials.UserName 但我没有这个级别的密码。

【问题讨论】:

  • 请使用标签而不是在您的标题中添加诸如“C# .NET 3.0”之类的内容。
  • 我对 WCF 中的安全性了解不多,但我猜你的问题在于AllowedImpersonationLevel。我会尝试使用TokenImpersonationLevel.Delegation msdn.microsoft.com/en-us/library/…
  • 我尝试了委托,我仍然得到在 WS2 端启动服务的 Web 用户。 :(
  • 匿名访问被禁用了?
  • 是的,我不想要匿名用户。我想了解用户,并使用 HttpContext.Current.User.Identity 来判断谁在尝试使用我的服务

标签: c# web-services .net-3.0 networkcredentials defaultnetworkcredentials


【解决方案1】:

这通常通过集中式身份验证服务完成,例如 CAS (http://www.jasig.org/cas)。

【讨论】:

    【解决方案2】:

    我没有在 C# 中编码,但看起来您想要的是使用您的 Web 服务调用发布凭据。

    为此,您需要将凭据附加到 HTTP 请求的正文中。

    【讨论】:

    • 哇,5 分钟,-2 分。我猜这不是你想要做的。
    猜你喜欢
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 2022-11-15
    • 1970-01-01
    • 1970-01-01
    • 2011-07-06
    相关资源
    最近更新 更多