Web Service怎样处理异常

MikeZhu 2003-03-20 08:57:11
Web Service怎样发出异常,客户端(WinForm)怎样捕捉异常。
...全文
107 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yqdeng 2003-03-26
  • 打赏
  • 举报
回复
一样的
qieyj 2003-03-20
  • 打赏
  • 举报
回复
捕获由 XML Web services 方法引发的异常

在 Try/Catch 块中,捕获 SoapException(任何由 XML Web services 方法引发的异常都以 SoapException 的形式引发)。
下面的代码示例是调用 XML Web services 方法的客户端捕获由 XML Web services 方法引发的异常。然后,客户端用所捕获的 SoapException 的属性填充 HTML 表。

[C#]
<%@ Import Namespace="System.Web.Services.Protocols" %>
<%@ Import Namespace="System.Xml" %>
<%@ Page Language="C#" %>
<html>
<head>
<script runat=server language=c#>
void Page_Load(Object o, EventArgs e){

// Create a new instance of the XML Web service proxy class.
ThrowSoapException throwSoapException = new ThrowSoapException();

// Make a call to the XML Web service method, which throws an
// exception.
try
{
throwSoapException.myThrow();
}
catch (SoapException error)
{
// Populate the table with the exception details.
ErrorTable.Rows.Add(BuildNewRow("Fault Code Namespace",
error.Code.Namespace));
ErrorTable.Rows.Add(BuildNewRow("Fault Code Name",
error.Code.Name));
ErrorTable.Rows.Add(BuildNewRow(
"Soap Actor that threw Exception", error.Actor));
ErrorTable.Rows.Add(BuildNewRow("Error Message",
error.Message));
ErrorTable.Rows.Add(BuildNewRow("Detail",
HttpUtility.HtmlEncode(error.Detail.OuterXml)));

return;
}

}
// This populates a row in an HtmlTable.
HtmlTableRow BuildNewRow(string Cell1Text, string Cell2Text) {
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell1 = new HtmlTableCell();
HtmlTableCell cell2 = new HtmlTableCell();

//Set the contents of the two cells.
cell1.Controls.Add(new LiteralControl(Cell1Text));
//Add a cell to the row.
row.Cells.Add(cell1);

cell2.Controls.Add(new LiteralControl(Cell2Text));

//Add a cell to the row.
row.Cells.Add(cell2);
return row;

}
</script>
<head>
<body>
<table id="ErrorTable" CellPadding=5 CellSpacing=0 Border="1" BorderColor="black" runat="server" />
</body>
glboy 2003-03-20
  • 打赏
  • 举报
回复
这跟其他程序的处理是一样的
dragontt 2003-03-20
  • 打赏
  • 举报
回复
在Web Service过程中
捕获到异常后,当作一种返回值返回
在客户端接受到这种返回值后
在作处理

laixiang 2003-03-20
  • 打赏
  • 举报
回复
常用这种方式:

try{}
catch{}
wsj 2003-03-20
  • 打赏
  • 举报
回复
Apache AXIS中规定了exception的SOAP表达

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧