c# - 有没有办法从 ASP.NET WebMethod 中获取原始 SOAP 请求?

标签 c# .net web-services soap asmx

例子:

public class Service1 : System.Web.Services.WebService
{
   [WebMethod]
   public int Add(int x, int y)
   {
       string request = getRawSOAPRequest();//How could you implement this part?
       //.. do something with complete soap request

       int sum = x + y;
       return sum;
   }
}

最佳答案

SoapExtensions 的替代方法是实现 IHttpModule 并在输入流传入时获取它。

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

关于c# - 有没有办法从 ASP.NET WebMethod 中获取原始 SOAP 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2587952/

相关文章:

.net - 定速巡航.NET

c# - 如何修复从不同网络登录网站帐户时出现的错误

c# - Environment.UserName 返回defaultAppPool

c# - 在没有 Flash 的情况下将实时音频流式传输到网站

.net - sendmessage api 选择组合框控件的特定索引

java - parseEagerly 在 MTOM 的 @StreamingAttachment (Metro) 中意味着什么

c# - 在方法中停止执行的最佳方法

c# - 如何等到 File.Exists?

c# - 服务引用使用数组而不是 List<Type>,即使设置说要使用 List

python - 如何安装 virtualenv 和/或 pip