Click here to Skip to main content
12,949,083 members (58,906 online)
Rate this:
 
Please Sign up or sign in to vote.
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 24-Feb-12 4:08am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,489
CHill60 3,330
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 24 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100