HttpListner:拦截对WCF数据服务的请求
我想使用.net类HttpListener拦截对我的自托管(WebServiceHost)WCF数据服务的请求,以便将“WWW Authenticate”头添加到响应中(用于用户身份验证)。但HttpListener似乎不拦截任何到我的数据服务的请求。HttpListner适用于不同的路径。示例:HttpListner:拦截对WCF数据服务的请求,wcf,wcf-data-services,basic-authentication,httplistener,Wcf,Wcf Data Services,Basic Authentication,Httplistener,我想使用.net类HttpListener拦截对我的自托管(WebServiceHost)WCF数据服务的请求,以便将“WWW Authenticate”头添加到响应中(用于用户身份验证)。但HttpListener似乎不拦截任何到我的数据服务的请求。HttpListner适用于不同的路径。示例:HttpListner前缀:有效:无效: 是否也可以通过HttpListner拦截到自托管WCF数据服务(WebServiceHost)的请求? 以下是相关的代码片段 承载WCF数据服务: WebSer
HttpListner前缀:
有效:
无效:
是否也可以通过HttpListner拦截到自托管WCF数据服务(WebServiceHost)的请求?
以下是相关的代码片段 承载WCF数据服务:
WebServiceHost dataServiceHost = new WebServiceHost(typeof(MyWCFDataService));
WebHttpBinding binding = new WebHttpBinding();
dataServiceHost.AddServiceEndpoint(typeof(IRequestHandler), binding,
"http://localhost/somePath/myWCFDataService");
dataServiceHost.Open();
HTTP Listner:
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你通过HttpListener代理搞错了。看一看 对不起,我想我已经留言了。感谢修复链接,但请根据提供上下文,以防再次移动。