Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can we capture a SOAP massage in asmx web method?

For example we need to create a method for client is sending a SOAP massage for checking a number even or odd,

<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<sone:check xmlns:sone="http://www.xxxx.com/webservices/schemas"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sone:Number xsi:type="xsd:string">4</sone:partnerLogin>
</sone:check>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


and we need to response them in SOAP itself iike below.

<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<sone:CheckResult xmlns:sone="http://www.xxxxxxxxx.com/webservices/schemas"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<sone:Result xsi:type="xsd:string">Number is even</sone:partnerLogin>
</sone:CheckResult >
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


using ASP.net and C#.

Thanks for help in advanced
Posted

1 solution

To capture SOAP request/response, you can implement IHttpModule and grab the input stream as it's coming in using the below code:

C#
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();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900