【发布时间】: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.Delegationmsdn.microsoft.com/en-us/library/… -
我尝试了委托,我仍然得到在 WS2 端启动服务的 Web 用户。 :(
-
匿名访问被禁用了?
-
是的,我不想要匿名用户。我想了解用户,并使用 HttpContext.Current.User.Identity 来判断谁在尝试使用我的服务
标签: c# web-services .net-3.0 networkcredentials defaultnetworkcredentials