我有一个System.Web.Services.WebService
包含几个WebMethods
。如果这些WebMethods
中的任何一个引发异常,我想记录传递给该WebMethod的值。我想以一种通用的方式处理这个问题,以便我可以使用相同的方法,而不管参数的数量或类型如何。我以为我会记录原始的JSON,但我无法确定如何访问它。我搜索了整个Context.Request对象(包括InputStream
属性),但没有找到它。从asp.net WebMethod内部访问原始JSON
这里是我想怎样做:
[WebMethod(EnableSession = true)]
public IEnumerable MyWebMethod(int a, string b)
{
try
{
//do something
}
catch (Exception e)
{
LogException(e, this.Context);
throw;
}
}
//All WebMethods should be able to call LogExceoption regardless of param type/count
protected void LogException(Exception ex, HttpContext context)
{
string parameters = context.Request. //?? i don't know how to get to the JSON
//write exception detail to log
}
我使用C#和.NET Framework 3.5的
疯狂,这是这么简单。 – 2010-08-22 04:42:24