調用webservice時,我需要在調用特定操作時更改響應文本。HttpModule更改響應
因此,我創建了HttpModule來捕獲響應並對其進行更改。
代碼如下:
public class BeginEnd : IHttpModule
{
public void Init(HttpApplication context)
{
context.EndRequest += (o, e) =>
{
HttpContext currContext = HttpContext.Current;
NameValueCollection collection = currContext.Request.QueryString;
if (collection.Count > 0
&& collection["op"] != null
&& collection["op"] == "ChangeService")
{
string xmlOther = "<root>My Test</root>";
currContext.Response.Clear();
currContext.Response.Write(xmlOther);
currContext.Response.End();
}
};
}
public void Dispose()
{
}
}
所以你看,我只是清楚Response對象,並把我的文字。
是一個正確的方法來做到這一點?
它的工作,但我覺得我失去了一些東西
你覺得呢?