1

我目前有一个调用 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 但我没有密码等级。

4

2 回答 2

0

这通常通过像 CAS ( http://www.jasig.org/cas ) 这样的集中式身份验证服务来完成。

于 2013-05-20T15:03:07.053 回答
-3

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

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

于 2012-01-25T19:40:21.180 回答