c# webservice -通过soap验证参数并抛出异常/错误
本文关键字:抛出异常 错误 参数 验证 webservice -通过 soap | 更新日期: 2023-09-27 18:08:22
验证WebMethod参数的最佳方法是什么?
我想这不是最佳实践:
[WebMethod]
public string HelloWorld(String sayHi)
{
if (sayHi.Equals(""))
{
throw new Exception("User not provided");
}
return "String OK";
}
谢谢
这个怎么样:
你应该使用string
而不是String
。
[WebMethod]
public string HelloWorld(string sayHi)
{
if (string.IsNullOrEmpty(sayHi)
throw new ArgumentException("User not provided");
return "String OK";
}