0

以下のコード スニペットを使用して、WCF サービスでクライアント ユーザー名を取得します。サーバーの 1 つで、間違ったクライアント名を取得しています。私のクライアントは Win7 で、ワークグループ構成で Server 2008R2 と通信しており、両方のマシンにユーザーDaveDave_Admin. どちらも Win7 の管理者であり、後者のみがサーバーの管理者です。問題は、クライアントを として起動Daveし、サーバーがクライアントを として表示することですDave_Admin。クライアントの Dave とサーバーの Dave_Admin として、接続の両側の ID をデバッグしました。クレーム リソースにもDave_AdminSID が表示されます。

これが起こると私が想像できる唯一の2つの理由は

  1. サーバーはどういうわけか、私が疑うユーザーDave_Adminを探しているか、またはDave
  2. セットアップ後、管理ユーザーの名前を に変更DaveDave_Admin、新しいユーザーDaveを標準ユーザーとして作成した可能性があります。

やったかもしれないという漠然とした記憶しかありませんが、やったかどうかはわかりません。c:\usersフォルダは正常に見えます。私がこれを行った場合、これが理由ですが、修正する方法はありますか?

ユーザーの名前を変更した後にこれが発生した場合、別の説明または修正手段がありますか?

OperationContext lContext = OperationContext.Current;
RemoteEndpointMessageProperty mEndpointMessageProperties = lContext.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

mIdentity = lContext.ServiceSecurityContext.WindowsIdentity;
mUserName = mIdentity.Name;
mIPAddress = mEndpointMessageProperties.Address;
mPort = mEndpointMessageProperties.Port;
mConsoleID = string.Format("IP:{0}Port:{1}", mIPAddress, mPort);
mCallbackInterface = lContext.GetCallbackChannel<IConsoleCallbacks>();
mAuthority = TxWcfServer.sSelf.Authorized(mIdentity); // get the user's authority from the WcfServer when they logged on

// show client information
if (AppSupport.IsLogLevel(LogLevel.WCF))
{
   // show the various security contexts
   var x = lContext.ServiceSecurityContext;
   AppSupport.WriteLog(LogLevel.Note, "*** WCF WindowsIdentity is '{0}'.", x.WindowsIdentity.Name);
   AppSupport.WriteLog(LogLevel.Note, "*** WCF PrimaryIdentity is '{0}'.", x.PrimaryIdentity.Name);
   AppSupport.WriteLog(LogLevel.Note, "*** WCF IsAnonymous is '{0}'.", x.IsAnonymous);

   foreach (ClaimSet claimset in ServiceSecurityContext.Current.AuthorizationContext.ClaimSets)
   {
      foreach (System.IdentityModel.Claims.Claim claim in claimset)
      {
          // Write out each claim type, claim value, and the right. There are two 
          // possible values for the right: "identity" and "possessproperty". 
          AppSupport.WriteLog(LogLevel.Note, "*** WCF Claim Type: {0}, Resource: {1} Right: {2}",
                        claim.ClaimType, claim.Resource.ToString(), claim.Right);
      }
   }
}    
4

1 に答える 1

0

コードがクライアント コンテキストを取得できるようにするには、WCF サービスで偽装を有効にする必要があります。そうしないと、サービス コンテキストを取得することになります (これがおそらく、サービスが Dave_Admin として実行されているため、Dave ではなく Dave_Admin を取得する理由です) )

この投稿には、有効にする方法に関する情報が記載されています: http://msdn.microsoft.com/en-us/library/ms730088.aspx

于 2012-12-20T22:11:03.730 に答える