Search code examples
asp.netweb-servicesiisiis-7asmx

IIS 7 Logging Web Service methods


I have a web service (not a WCF service) hosted under IIS 7, the web service has two methods: method1, and method2.

I am looking to differentiate between the requests for method1, versus the requests for method2, without modifying the web service code.

Under the IIS 7 logs, I can see the requests to the web service, the web service URL gets logged under the "cs-uri-stem" field, but the "cs-uri-query" field is empty.

Is there anyway to log the requests for the web service methods, without modifying the web service code?


Solution

  • You can log all incoming request inside various methods of the processing pipeline. For example, add a handler for BeginRequest in your Global.asax:

    Application_BeginRequest( object sender, EventArgs e )
    {
        HttpApplication app = (HttpApplication)sender;
        HttpContext ctx = app.Context;
    
        var requestUrl = ctx.Request.Url;
    
        // the uri should be of a form:
        // http://yoursite/theservice.asmx/MethodName
    }