新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
如何獲取WebService的請(qǐng)求信息-創(chuàng)新互聯(lián)
本篇文章為大家展示了如何獲取WebService的請(qǐng)求信息,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。

首先想到的是在每一個(gè)帶有WebMethod特性的方法里調(diào)用記錄請(qǐng)求信息的方法,這樣可以記錄信息,但是太多帶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 "用戶名或密碼錯(cuò)誤";
}
}這里使用了Log4Net將請(qǐng)求信息記錄起來(lái)




另一種調(diào)用方式是在另一個(gè)項(xiàng)目中添加了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"));
}
}上述內(nèi)容就是如何獲取WebService的請(qǐng)求信息,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當(dāng)前文章:如何獲取WebService的請(qǐng)求信息-創(chuàng)新互聯(lián)
本文網(wǎng)址:http://fisionsoft.com.cn/article/hisis.html


咨詢
建站咨詢
