Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the raw SOAP request from within a ASP.NET WebMethod?

Example:

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;
   }
}
like image 622
Francisco Noriega Avatar asked Apr 06 '10 20:04

Francisco Noriega


People also ask

Can Postman be used for SOAP Services?

Postman is a clean, easy-to-use REST client, but it also works well for sending SOAP message via HTTP. Configuring Postman for a SOAP request is similar to a REST configuration.


1 Answers

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();
    }
}
like image 129
nivlam Avatar answered Sep 18 '22 13:09

nivlam