Дуплексный обратный вызов всегда анонимный

Я написал дуплексный сервис и клиент WCF. Все работает хорошо, пока я не попытаюсь вызвать .Demand() в клиентской реализации. Похоже, что служба вызывает метод обратного вызова анонимно. Я думаю, что мне не хватает того, как правильно настроить службу.

Код, используемый для создания 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!");

Код, используемый для создания клиента;

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();

Реализация клиента:

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

Как настроить так, чтобы ServiceHost правильно вызывал обратный вызов с учетными данными Windows?


person Community    schedule 18.02.2009    source источник


Ответы (1)


Устанавливает ли TokenImpersonationLevel значение делегирования вместо олицетворения? Как это:

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

См. эту статью MSDN.

person Fredrik    schedule 29.01.2013
comment
Копатель могил? :) Вопрос был задан 18 февраля 2009 года, и запрашивающий пользователь был удален за неактивность, я думаю, давно. - person abatishchev; 29.01.2013