我有一个System.Web.Services.WebService
包含几个WebMethods
. 如果其中任何一个WebMethods
引发异常,我想记录传递给该 WebMethod 的值。我想以一种足够通用的方式处理这个问题,无论参数的数量或类型如何,我都可以使用相同的方法。我以为我会记录原始 JSON,但我无法确定如何访问它。我搜索了整个 Context.Request 对象(包括InputStream
属性),但没有找到它。
这是我想做的事情:
[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
}
我正在使用带有 .net Framework 3.5 的 C#