locked
how i can capture the asp.net web service request response RRS feed

  • Question

  • User-775697465 posted

    I have an asp.net web service , i want to log and store each request resopnse for this web service , so how can i capture the web each web service request/ response message so i can store it in the harddesc as txt files.

    Many thanks for your help.

    Thursday, November 21, 2013 3:05 AM

Answers

  • User260886948 posted

    Hi,

    One way to capture the raw message is to use SoapExtensions.

    An alternative to SoapExtensions is to implement IHttpModule and grab the input stream as it's coming in, it should be something like this:

    public class LogModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += this.OnBegin;
        }
    
        private void OnBegin(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            HttpContext context = app.Context;
    
            byte[] buffer = new byte[context.Request.InputStream.Length];
            context.Request.InputStream.Read(buffer, 0, buffer.Length);
            context.Request.InputStream.Position = 0;
    
            string soapMessage = Encoding.ASCII.GetString(buffer);
    
            // Do something with soapMessage
        }
    
        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }


    Best Regards,
    Amy Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 22, 2013 2:46 AM

All replies

  • User-488622176 posted

    This question has been answerred in this post : http://forums.asp.net/t/1857494.aspx

    Thursday, November 21, 2013 8:13 AM
  • User260886948 posted

    Hi,

    One way to capture the raw message is to use SoapExtensions.

    An alternative to SoapExtensions is to implement IHttpModule and grab the input stream as it's coming in, it should be something like this:

    public class LogModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.BeginRequest += this.OnBegin;
        }
    
        private void OnBegin(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            HttpContext context = app.Context;
    
            byte[] buffer = new byte[context.Request.InputStream.Length];
            context.Request.InputStream.Read(buffer, 0, buffer.Length);
            context.Request.InputStream.Position = 0;
    
            string soapMessage = Encoding.ASCII.GetString(buffer);
    
            // Do something with soapMessage
        }
    
        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }


    Best Regards,
    Amy Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 22, 2013 2:46 AM