6

私は 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 資格情報を使用してコールバックを正しく呼び出すように構成するにはどうすればよいですか?

4

1 に答える 1

0

TokenImpersonationLevel を Impersonation ではなく Delegation に設定しますか? このような:

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

この MSDN の記事を参照してください。

于 2013-01-29T07:35:54.563 に答える