如何从Web Service获取错误

编程入门 行业动态 更新时间:2024-10-25 23:33:07
本文介绍了如何从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获取错误

本文发布于:2023-11-26 15:26:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634268.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Web   Service

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!