È possibile anche leggere il contents of the Request.InputStream.
In questo modo è più utile per i casi in cui si desidera eseguire la convalida o altre azioni all'interno del metodo Web a seconda del contenuto dell'input.
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;
}
}
}
NOTA: aggiornato per riflettere Johns commento qui sotto.
fonte
2011-05-21 02:01:22
forse ovvio, ma potrebbe essere necessario registrare l'IHttpModule nel web.config –