I am new to web services and need to capture SOAP XML messages that will be sent to my web service. I found article that says you can read the contents of the Request.InputStream from within your asmx WebMethod.
Capturing SOAP requests to an ASP.NET ASMX web service
Code is as follows:
using System;
using System.Collections.Generic;
using System.Web;
using System.Xml;
using System.IO;
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace SoapRequestEcho
{
[WebService(
Namespace = "http://soap.request.echo.com/",
Name = "SoapRequestEcho")]
public class EchoWebService : WebService
{
[WebMethod(Description = "Echo Soap Request")]
public XmlDocument EchoSoapRequest(int input)
{
// Initialize soap request XML
XmlDocument xmlSoapRequest = new XmlDocument();
// Get raw request body
Stream receiveStream = HttpContext.Current.Request.InputStream
// Move to begining of input stream and read
receiveStream.Position = 0;
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
// Load into XML document
xmlSoapRequest.Load(readStream);
}
// Return
return xmlSoapRequest;
}
}
}
However, I am confused because this asks for an int input parameter. I suppose I could just remove it, but I am not sure how the external user would call my web service and post an XML message to it. How could I perform a test on this to send it XML messages and make sure I can capture them in the stream? Any tips or links would be greatly appreciated, thanks.