Capture SOAP Envelope using ASP.net

I wanted to use the jQuery to post a 3rd party webservice call. First step is to understand the SOAP envelope. With soapUI, I was able to construct the SOAP envelope from the WSDL. However, the API involves complexType with objects inside nested arrays. The base envelope was not useful to me.

Since I’m not familiar with constructing complexType xml from scratch, I have to find an easy way to build the xml. The best route is to trace the exact SOAP call from my other .net application. So i built a simple ASP web application to capture the service call.

In the code behind, the ASP writes the data from Request.InputStream into a local file.

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (string o in Request.Params)
        {
            Response.Write(o + " : <span style='color:#a3a3a3'>" 
                 + Request[o] 
                 + "</span><br/>" 
                 + System.Environment.NewLine);
        }
        Stream file = File.OpenWrite(Server.MapPath("RequestStream.txt"));
        CopyStream(Request.InputStream, file);
        file.Flush(); 
        file.Close();

    }
}

found this code snippet to write stream data into a file


    public void CopyStream(Stream input, Stream output)
    {
        byte[] buffer = new byte[8 * 1024];
        int len;
        while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
        {
            output.Write(buffer, 0, len);
        }
    } 

By changing the URL (to the url of this ASP site) on my other .net application, I was able to capture the content of the SOAP envelope.