c# – 有没有办法从ASP.NET WebMethod中获取原始的SOAP请求?
发布时间:2020-12-15 06:53:34 所属栏目:百科 来源:网络整理
导读:例: 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;
例:
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(); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |