提问人:Tony Gomes 提问时间:10/9/2023 最后编辑:marc_sTony Gomes 更新时间:10/9/2023 访问量:22
有没有办法将异常属性应用于 asp.net Web 服务?
Is there any way to apply exception attribute to asp.net web service?
问:
我正在开发一个具有以下方法的 Web 服务,我想创建一个异常属性,以便如果需要,我可以将该属性注入到 Web 服务中的其他函数上并记录错误。
代码如下:
[WebMethod]
public string SwitchGetEmployeeLeaveBalances(string Str)
{
LeaveModel objLeaveModel = ObjectDeserializer.Deserialize<LeaveModel>(Str);
string requestString = JsonConvert.SerializeObject(objLeaveModel);
DateTime? _requestSentTime = objLeaveModel.RequestTime;
string res = "";
try
{
// get current request received time
_reqRecTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
AppMFSService.AppMFSServiceSoapClient mfs = new AppMFSService.AppMFSServiceSoapClient();
res = mfs.AppGetEmployeeLeaveBalances(Str);
List<Response> response = ObjectDeserializer.Deserialize<List<Response>>(res);
_status = response.DefaultIfEmpty().First().Status;
if (response.DefaultIfEmpty().First().Data != "")
_result = response.DefaultIfEmpty().First().Data;
else
_result = response.DefaultIfEmpty().First().Status;
_reqResTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
}
catch (Exception ex)
{
_status = ex.ToString();
_result = ex.ToString();
}
try
{
// creating routing transaction model
rTrx = new RoutingTransaction(Convert.ToInt32(objLeaveModel.TerminalID), "001", "001", "", objLeaveModel.MobileNumber, objLeaveModel.AccountNo, "", _reqRecTime.ToString(), _requestSentTime.ToString(), _result, _reqResTime, _status, "0", "059", GetServiceAddress.getMfsAppAddress(), objLeaveModel.UserName, objLeaveModel.TellerName, requestString);
// store routing transaction into switch routing transaction table
client = new StoreSwitchRouting(rTrx);
// calling transaction routing storing method
client.store();
}
catch (Exception ex)
{
//_result = string.Join("*", new string[] { _result, "Storing into transaction table failed" });
Logs.log(ex.ToString());
}
return res;
}
我尝试创建一个文件并在方法上添加日志记录逻辑,但这只会使日志记录功能在应用程序级别出现异常。global.asax.cs
Application_error
答: 暂无答案
评论