0

How can I use my httpmodules class with httplistener web service

here is my http module code as :

using System;  
using System.Web;   
using System.Collections;  

public class MyCustomHttpModule: IHttpModule 
{  
    public String ModuleName 
    {   
        application.BeginRequest += (new EventHandler(this.Application_BeginRequest));  
        application.EndRequest += (new EventHandler(this.Application_EndRequest));  
    }  

    private void Application_BeginRequest(Object source, EventArgs e) 
    {  
        HttpApplication application = (HttpApplication)source;  
        HttpContext context = application.Context;  
        context.Response.Write("<h1>MyCustomHttpModule: Beginning of Request...</h1><br/>");  
    }  

    private void Application_EndRequest(Object source, EventArgs e) 
    {  
        HttpApplication application = (HttpApplication)source;  
        HttpContext context = application.Context;  
        context.Response.Write("<h1>MyCustomHttpModule: End of Request...</h1>");  
    }          

    public void Dispose()   
    {  
    }  
}  

httplistener code as below :

using HttpListener = HttpServer.HttpListener;

public class Loader
{
    static void Main(string[] args)
    {
        HttpListener listener = HttpListener.Create(IPAddress.Any, 8089);
        DynamicModuleUtility.RegisterModule(typeof(FileWebDAVModule));
        listener.Start(5);
        Thread.Sleep(90000000);
    }

}

How can I call my httpmodule with httplistener service. Kindly guide me.

gooid
  • 841
  • 8
  • 18
  • It is not clear what you mean by 'call my httpmodule with httplistener service', please provide a better example (see http://sscce.org)/ – gooid Nov 06 '13 at 10:56
  • above httpmodule class use to call http request & response, and this class i want to use in web service, which is working through http listner with ip & and selected port, when i m going to run those service through http listener, i want to get request & response through my http module – irfan shaikh Nov 06 '13 at 11:37
  • Unless your HttpModule knows to look for an HttpListenerContext rather than an HttpContext, this will be difficult. I've been having my modules get the HttpContext and then wrap it with HttpContextWrapper to get the HttpContextBase abstraction. Then, I still need to write a similar wrapper for the HttpListenerContext. – Mark Melville May 27 '14 at 17:05

0 Answers0