Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SOAP
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 5: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)



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 24 Feb 2012
Copyright © CodeProject, 1999-2014
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