捕获对 ASP.NET ASMX Web 服务的 SOAP 请求 [英] Capturing SOAP requests to an ASP.NET ASMX web service

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

问题描述

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

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

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

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