0

.netクラスのHttpListenerを使用して、自己ホスト型(WebServiceHost)WCFデータサービスへの要求をインターセプトし、応答に「WWW-Authenticate」ヘッダーを追加します(ユーザー認証用)。しかし、HttpListenerは私のデータサービスに送られるリクエストを傍受していないようです。HttpListnerは、さまざまなパスで問題なく機能します。例:

HttpListnerプレフィックス:http:// localhost / somePath /動作
http:// localhost / somePath /動作
しない:http:// localhost / somePath / myWCFDataService

HttpListnerを使用して自己ホスト型WCFデータサービス(WebServiceHost)に送信される要求もインターセプトすることは可能ですか?
関連するコードスニペットは次のとおりです...

WCF DataServiceのホスティング:

WebServiceHost dataServiceHost = new WebServiceHost(typeof(MyWCFDataService));
WebHttpBinding binding = new WebHttpBinding();
dataServiceHost.AddServiceEndpoint(typeof(IRequestHandler), binding, 
    "http://localhost/somePath/myWCFDataService");
dataServiceHost.Open();

HTTPリストナー:

HttpListener httpListener = new HttpListener();
httpListener.Prefixes.Add("http://localhost/somePath/");
httpListener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
httpListener.Start();

while (true)
{
    HttpListenerContext context = httpListener.GetContext();
    string authorization = context.Request.Headers["Authorization"];

    if (string.IsNullOrEmpty(authorization))
    {
         context.Response.StatusCode = 401;
         context.Response.AddHeader("WWW-Authenticate", "Basic realm=\"myDataService\"");
         context.Response.OutputStream.Close();
         context.Response.Close();
    }
}

WCFデータサービス内でHTTP基本認証を行うためのより良い方法はありますか?Webブラウザのログインダイアログで認証できません。

どうもありがとう、
JeHo

4

1 に答える 1

-1

HttpListenerを介したプロキシをいじって間違ったツリーを吠えています。これを見てください。

于 2010-02-26T04:10:37.680 に答える