うまくいけば、皆さんは私のためにこれのいくつかを明確にすることができます. Sql メンバーシップ プロバイダーを使用する Web アプリケーションがあり、WCF サービスを介して 2 番目の Web アプリケーションと通信します。どちらのアプリケーションも同じ Sql メンバーシップ プロバイダー データストアを共有していますが、ユーザーを認証するために各 WCF サービス呼び出しが必要です。
さて、私は多くのサンプルを見てきましたが、私が見たサンプルでは、特定のコードが省略されているように感じます。それは、私には明らかな「はず」であるか、WCF が要求を処理する方法を誤解しています (期待値を参照)。以下のコード)。
どんな助けにも感謝しています...
ここに私がすでに知っている方法があります
- 両端で Sql メンバーシップを構成する方法を知っています。
- wsHttpBinding のセットアップ方法を知っている
- トランスポート セキュリティで使用されるサービス証明書を設定する方法を知っています
これが私が混乱しているものです
- メンバーシップパスワードを渡すにはどうすればよいですか (...できません)
- 認証 Cookie を渡しますか? もしそうなら、どのように?
- ユーザー (自分自身) に関係のない「既知の」ユーザー名とパスワードを作成しますか?
Web クライアントでは、このようなコードが表示されることを期待しています
protected void btnLogin_Click(object sender, EventArgs e)
{
// Logging into the web-application is known and easy.
if (Membership.ValidateUser("MyUserName", "MyPassword"))
{
FormsAuthentication.SetAuthCookie("MyUserName", true);
FormsAuthentication.RedirectFromLoginPage("MyUserName", false);
}
}
protected ServiceReference1.Contractor getContractor(Int32 key)
{
// I expect something "like" this on the client call.
MembershipUser user = Membership.GetUser("MyUserName");
ServiceReference1.FishDataClient wcfService = new ServiceReference1.FishDataClient();
// You can't retreive the users password directly,
// nor can you get the hash from the SqlMembershipProvider.
wcfService.ChannelFactory.Credentials.UserName.UserName = user.UserName;
// So doing something like this would not be possible.
wcfService.ChannelFactory.Credentials.UserName.Password = "??????";
// So how is the web service going to authenticate the user from it's
// references to the same SqlMembershipProvider (database).
ServiceReference1.Contractor contractor = wcfService.GetContractor(key);
wcfService.Close();
wcfService = null;
return contractor;
}
WCF サービスでは、このようなコードが表示されることを期待しています
[PrincipalPermission(SecurityAction.Demand, Role = "User")]
public Contractor GetContractor(Int32 key)
{
ServiceSecurityContext context = ServiceSecurityContext.Current;
Contractor contractor = new Contractor();
// What goes here? I would expect something like this...
if (Membership.ValidateUser("???????", "???????"))
contractor.Get(key);
return contractor;
}