私はWCFクライアントとリモートインターネットWCFサーバーの両方を書いています。C#:WCF認証、ユーザー名+ SSLを追加する方法?
リモートWCFサーバーは、従来のWindowsサービスラッパー(つまりIISではなく)でホストされているWPFを実行しています。
現在、基本的なHTTPバインディングと完全に連携しています。私はVisual Studio 2010 + .NET 4.0 + C#を使用しています。
誰でも私のコードを変更してユーザー名+ SSL認証を追加できるように正しい手順の指示に従えますか?
EDIT:サービスの終わりに
、次のように私はUserNamePasswordValidatorを上書きしました:
:public class CustomUserNameValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
Console.WriteLine("Got to here");
}
}
サービス終了時に、私は、ユーザー名の検証クラスへのリンクを指定しましたクライアント側で
ServiceHost serviceHost = new ServiceHost(typeof(PhiFeedServer.PhiFeed)); // ,baseAddress);
const bool passswordAuthentication = true;
if (passswordAuthentication)
{
// These two lines switch on username/password authentication (see custom class "CustomUserNameValidator" in common file PhiFeed.svc.cs)
// See http://msdn.microsoft.com/en-us/library/aa354513.aspx
serviceHost.Credentials.UserNameAuthentication.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom;
serviceHost.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustomUserNameValidator();
}
// Start the service
serviceHost.Open();
:
EndpointAddress endpointAddress = new EndpointAddress("http://localhost:20000/PhiFeed?wdsl");
BasicHttpBinding serviceBinding = new BasicHttpBinding();
serviceBinding.ReceiveTimeout = new TimeSpan(0, 0, 120);
proxy = new PhiFeedClient(serviceBinding, endpointAddress);
proxy.ClientCredentials.UserName.UserName = "myusername";
proxy.ClientCredentials.UserName.Password = "mypassword";
しかし、すべてを実行すると、ユーザー名バリデーターを呼び出すことはありません - 何が起こっていますか?
basichttpで動作しますか?私は個人的には、wsHttpBindingまたはnet.tcpバインディングをprefferだろう。それと証明書を使うことができるからです:)。 – user507779
私の現在のセットアップではwsHttpBindingを使用しているので、証明書を使用できます。上記のコードは正しく動作していませんでした。 – Contango