一个已经写好的项目中有多个WebService,由于之前没有记录请求信息的,有时候需要查错等需要找到当次的请求信息,所以需要加入记录请求信息的功能。
首先想到的是在每一个带有WebMethod特性的方法里调用记录请求信息的方法,这样可以记录信息,但是太多带WebMethod特性的方法了,于是想在全局中拦截并捕获,于是想到了Global.asax
public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { } protected void Session_Start(object sender, EventArgs e) { } protected void Application_BeginRequest(object sender, EventArgs e) { if (Request != null) { try { if (".asmx".Equals(Request.CurrentExecutionFilePathExtension,StringComparison.OrdinalIgnoreCase) && Request.ContentLength > 0) { using (MemoryStream ms = new MemoryStream()) { Request.InputStream.CopyTo(ms); ms.Position = 0; using (StreamReader reader = new StreamReader(ms)) { LogHelper.Info(reader.ReadToEnd()); } } } } catch (Exception) { } finally { Request.InputStream.Position = 0; } } } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } protected void Application_Error(object sender, EventArgs e) { } protected void Session_End(object sender, EventArgs e) { } protected void Application_End(object sender, EventArgs e) { } }
[WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public string QueryBalance(string username,string password) { if (username == "test" && password == "abcd") { return "1000000"; } else { return "用户名或密码错误"; } }
这里使用了Log4Net将请求信息记录起来
另一种调用方式是在另一个项目中添加了WerService的引用,
public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { TestWebServiceSoapClient client = new TestWebServiceSoapClient(); Response.Write(client.QueryBalance("test","abcd")); } }
以上这篇获取WebService的请求信息方法实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持站长技术。
上篇文章给大家介绍了 Java正则表达式匹配,替换,查找,切割的方法 ,接下来,...
项目中用到的一些特殊字符和图标 html代码 XML/HTML Code 复制内容到剪贴板 div ...
复制代码 代码如下: % URL="http://news.163.com/special/00011K6L/rss_newstop....
正则忽略大小写 – RegexOptions.IgnoreCase 例如: 复制代码 代码如下: Str = R...
工具:Eclipse,Oracle,smartupload.jar;语言:jsp,Java;数据存储:Oracle。...
错误描述: 在开发.net项目中,通过microsoft.ACE.oledb读取excel文件信息时,报...
本文实例讲述了Laravel框架源码解析之反射的使用。分享给大家供大家参考,具体如...
DELETEFROMTablesWHEREIDNOTIN(SELECTMin(ID)FROMTablesGROUPBYName) Min的话保...
Elasticsearch 是通过 Lucene 的倒排索引技术实现比关系型数据库更快的过滤。特...
4月11日20:30~22:00通过腾讯会议进行了第二次在线学习讨论我把学习笔记整理一下...