views:

82

answers:

4

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

thanks!

A: 

Can you access the Request object? That's my guess for where to look to get that data.

JB King
+1  A: 

I assume you are wanting to log the SOAP request for tracing; perhaps you have a consumer of your service that is telling you they're sending you good SOAP, but you don't believe them, yes?

In that case, you should (temporarily) enable trace logging on your service.

If you are trying to do general purpose logging, don't bother with the SOAP packet, since it's heavy; your logs would bloat up quick. Just log the important stuff, like e.g. "Add called, X=foo, Y=bar".

Randolpho
Unfortunately it needs to be permanent, so I cant enable the trace just temporarily.
Francisco Noriega
@bangoker: Although you've found a solution that fills your immediate need, I suggest you reconsider your course. Logging every SOAP request is heavy and extremely unnecessary.
Randolpho
+3  A: 

Yes, you can do it using SoapExtensions. Here's a nice article that runs through the process.

Eric Petroelje
I think thats what I was looking for, thanks!
Francisco Noriega
+1  A: 

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