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