如何从Web Service获取错误 [英] How to get errors from Web Service

查看:97
本文介绍了如何从Web Service获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个连接数据库的c#Web服务,将数据检索到数据集中,并将该数据集返回到也用C#编写的独立应用程序。我可以在我的应用程序中显示该数据。



我的问题是:当Web服务遇到问题时,例如'无法获得oracle连接',因为数据库可能已关闭......



如何将错误消息从Web服务返回到我的应用程序并将其显示在消息框中?

I wrote a c# Web Service that connects to database, retrieves data into a dataset and returns that dataset to a Stand alone application also written in C#. I can display that data in my application.

My Question is: When the Web service encounters a problem, such as 'unable to get oracle connection' because maybe the database is down...

How do I return the error message from the web service to my application and display it in a Message Box?

推荐答案

Quote:

通过抛出异常来将错误传播回客户端。 Web服务方法可以通过以下方式执行此操作:

- 抛出SoapException异常。

- 抛出SoapHeaderException异常。

- 投掷特定于该问题的异常。

- 允许ASP.NET抛出异常。

Propagating errors back to a client is done by throwing exceptions. A Web service method can do this in the following ways:
- Throw a SoapException exception.
- Throw a SoapHeaderException exception.
- Throw an exception specific to the problem.
- Allow ASP.NET to throw the exception.





阅读文档并检查哪种方式最适合您的要求。



处理和抛出XML Web Services中的异常 [ ^ ]

如何:从使用ASP.NET创建的Web服务中抛出异常 [ ^ ]

如何:处理Web服务方法引发的异常 [ ^ ]



Read the documentation and check which way is most suitable for your requirements.

Handling and Throwing Exceptions in XML Web Services[^]
How to: Throw Exceptions from a Web Service Created Using ASP.NET[^]
How to: Handle Exceptions Thrown by a Web Service Method[^]


这篇关于如何从Web Service获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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