且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

捕获对 ASP.NET ASMX Web 服务的 SOAP 请求

更新时间:2022-06-25 23:40:58

捕获原始消息的一种方法是使用 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();
    }
}