Web服务异常 [英] Webservice Exception

查看:173
本文介绍了Web服务异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以捕获通过URL传递到Web服务的错误参数?例如,给定以下简单的webservice方法:

Is there any way to catch a bad parameter passed into a web service via URL? for example, given the following trivial webservice method:

public class MyWebService : System.Web.WebServices
{
    [WebMethod(Desciption="My WebService")]
    public int MyMethod( int number )
    {
       return number * 2;
    }
}



通过URL调用它,但传入一个无效的int:



Call it via a URL, but pass in an invalid int:

http://localhost/MyWebService.asmx/MyMethod?number=three


这将向用户显示一个难看的错误消息.有什么方法可以捕获此错误并更优雅地处理它?<​​br/>
谢谢.


This will display a rather ugly error message to the user. Is there any way to catch this error and handle it more elegantly?

Thanks.

推荐答案

我想您需要接受一个字符串作为参数,这与您想要的内容相反,以便被接受并为您代码来解析它并确定其是否有效以及如何响应.
I guess you need to accept a string as a param, which is counterintuitive to what you want, in order for it to be accepted, and for your code to parse it and decide if it''s valid or not, and how to respond.


这篇关于Web服务异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆