捕捉SOAP请求到ASP.NET ASMX web服务 [英] Capturing SOAP requests to an ASP.NET ASMX web service

查看:277
本文介绍了捕捉SOAP请求到ASP.NET ASMX web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑要求记录传入SOAP请求到ASP.NET ASMX Web服务。任务是捕获的原始XML被发送到web服务。

Consider the requirement to log incoming SOAP requests to an ASP.NET ASMX web service. The task is to capture the raw XML being sent to the web service.

需要记录的调试检查传入的消息。该应用程序已经在使用它自己的日志库,所以理想的用法是这样的:

The incoming message needs to be logged for debug inspection. The application already has its own logging library in use, so the ideal usage would be something like this:

//string or XML, it doesn't matter.
string incomingSoapRequest = GetSoapRequest();

Logger.LogMessage(incomingSoapRequest);


  • 是否有任何简单的解决方案来捕获传入SOAP请求的原始XML?

  • 您会处理这事件可以访问到该对象和相关属性?

  • 反正是有IIS可以捕获传入的请求,并推到一个日志?

  • 推荐答案

    一捕捉到的原始信息的方法是使用的 SoapExtensions

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

    要SoapExtensions的替代方法是实施IHttpModule的抢,因为它在未来的输入流。

    An alternative to SoapExtensions is to implement IHttpModule and grab the input stream as it's coming in.

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

    这篇关于捕捉SOAP请求到ASP.NET ASMX web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆