因此,我试图强制用户将值放入WebService中...但是,如果用户发送一个或多个空参数,则此WebService只会返回一个错误。
重点是,我希望捕获错误并将其保存在日志中,这或多或少就是我目前所拥有的:
string[] ResponseArray = new string[2];
[WebMethod(Description = "blahblahblah", EnableSession = false)]
public string[] exampleWS(int param_1, int param_2, ... , int param_n)
{
try
{
"WSLogic and code"
}
catch(Exception Ex)
{
"Code to call error log (custom made error log for DB)"
ResponseArray[0] = Ex.Message;
ResponseArray[1] = "Error's Date and Time";
}
}因此,如果用户调用此WebService,例如,他忘记了一个参数并将其留为null,则用户将得到类似以下内容:
Cannot convert into System.Int32.
Parameter name: type -------> blah blah error message blah blah我想要做的实际上是捕获此消息并调用日志并注册此错误,但在这种情况下我不知道如何调用异常,因为它甚至没有输入Try/Catch代码。
发布于 2014-11-29 07:57:12
在这种情况下,您可以使用nullable types。例如:
public string[] exampleWS(int? param_1, int? param_2, ... , int? param_n)https://stackoverflow.com/questions/27197134
复制相似问题