J'ai écrit un service duplex WCF et un client. Tout fonctionne bien jusqu'à ce que j'essaie d'appeler .Demand() dans l'implémentation du client. Il semble que le service invoque la méthode de rappel de manière anonyme. Je pense qu'il me manque comment configurer correctement le service.Le rappel duplex est toujours anonyme
Code utilisé pour créer 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!");
Code utilisé pour créer le client;
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();
mise en œuvre du client:
public void MethodOnClient(string message)
{
Console.WriteLine(Thread.CurrentPrincipal.Identity.Name); // <-- anonymous
PrincipalPermission p = new PrincipalPermission(@"DOMAIN\User", null);
p.Demand(); // <-- fails
}
Comment puis-je configurer pour que le ServiceHost appelle correctement le rappel avec les informations d'identification de Windows?
Pépiniériste? :) La question a été posée le 18 février 2009 et l'utilisateur demandé a été supprimé pour inactivité, je suppose qu'il y a longtemps. – abatishchev