Pregunta

Quiero utilizar la clase .NET HttpListener a las solicitudes de interceptación a mi selfhosted (WebServiceHost) WCF Data Service con el fin de agregar el encabezado "WWW-Authenticate" a la respuesta (para la autenticación de usuario). Pero parece que la HttpListener no hace ninguna solicitud de intercepción que van a mi Dataservice. El HttpListner trabaja para diferentes caminos muy bien. Ejemplo:
HttpListner Prefijo: http: // localhost / somepath /
Works: < a href = "http: // localhost / somepath /" rel = "nofollow noreferrer"> http: // localhost / somepath /
no funciona: http: // localhost / somepath / myWCFDataService

¿Es posible intercepción solicita también que ir a un servicio de datos WCF selfhosted (WebServiceHost) con el HttpListner?
Éstos son los fragmentos de código relevante ...

La celebración de la WCF DataService:

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

El 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();
    }
}

¿Hay una mejor manera de hacer la autenticación HTTP básica dentro de WCF Data Services? Me wa ser capaz de autenticar a través de la ventana de acceso del navegador web.

Muchas gracias,
Jeho

¿Fue útil?

Solución

Usted está ladrando al árbol equivocado Messing con proxy a través de HttpListener. Echar un vistazo a este .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top