我目前有一個應用程序調用Web服務(WS1),該服務又調用另一個Web服務(WS2)來獲取/設置WS2上託管的服務器上的信息。我希望能夠將用戶憑證從WS1傳入WS2,就好像有一個應用程序直接調用到WS2中一樣。有沒有辦法做到這一點?如何將證書從一個Web服務傳遞給另一個?
這是我目前:
應用代碼:
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'嘗試它http://msdn.microsoft.com/en-us/library/system.security.principal.tokenimpersonationlevel.aspx –
我試過委派,我仍然得到啓動WS2方面的服務。 :( – Tizz