2009-02-18 23 views
6

Napisałem usługę dupleksową i klienta WCF. Wszystko działa dobrze, dopóki nie spróbuję wywołać metody .Demand() w implementacji klienta. Wygląda na to, że usługa wywołuje metodę zwrotną anonimowo. Myślę, że brakuje mi tego, jak poprawnie skonfigurować usługę.Oddzwanianie dupleksowe jest zawsze anonimowe.

Kod używany do utworzenia ServiceHost;

ServiceHost duplex = new ServiceHost(new ServerWCallbackImpl());   
NetTcpBinding secureBinding = new NetTcpBinding(SecurityMode.Message); 
secureBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; 
duplex.AddServiceEndpoint(typeof(IServerWithCallback), 
    secureBinding, 
    "net.tcp://localhost:9080/DataService"); 
Console.WriteLine(Thread.CurrentPrincipal.Identity.Name); //<-- this correctly shows the current principal 
duplex.Open(); 
if (duplex.State == CommunicationState.Opened) 
    ((ServerWCallbackImpl)duplex.SingletonInstance).Send("Hello World!"); 

Kod używany do utworzenia klienta;

CallbackImpl callbackInstance = new CallbackImpl(); 
NetTcpBinding secureBinding = new NetTcpBinding(SecurityMode.Message); 
secureBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; 
DuplexChannelFactory<IServerWithCallback> cf = new DuplexChannelFactory<IServerWithCallback>(
    callbackInstance, 
    secureBinding, 
    new EndpointAddress(requestingEndpointAddress));   
cf.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; 
cf.Credentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials; 
IServerWithCallback srv = cf.CreateChannel(new InstanceContext(callbackInstance)); 
srv.InitiateConversation(); 

wdrożenie Klient:

public void MethodOnClient(string message) 
{ 
    Console.WriteLine(Thread.CurrentPrincipal.Identity.Name); // <-- anonymous 
    PrincipalPermission p = new PrincipalPermission(@"DOMAIN\User", null); 
    p.Demand(); // <-- fails 
} 

jaki sposób można skonfigurować tak, aby ServiceHost poprawnie wywołuje oddzwaniania z poświadczeń systemu Windows?

Odpowiedz

0

Czy ustawienie TokenImpersonationLevel na delegowanie zamiast personifikacji? W ten sposób:

cf.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation; 

Zobacz this MSDN article.

+0

Koparka kamieniami? :) Pytanie zostało zadane w lutym 18 '09, a użytkownik pytający został usunięty z powodu braku aktywności, jak sądzę dawno temu. – abatishchev