例:
public class Service1 : System.Web.Services.WebService { [WebMethod] public int Add(int x,int y) { string request = getRawSOAPRequest();//How could you implement this part? //.. do something with complete soap request int sum = x + y; return sum; } }
解决方法
SoapExtensions的替代方法是实现IHttpModule,并在输入流中获取输入流.
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,buffer.Length); context.Request.InputStream.Position = 0; string soapMessage = Encoding.ASCII.GetString(buffer); // Do something with soapMessage } public void Dispose() { throw new NotImplementedException(); } }