一个已经写好的项目中有多个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")); } }
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级