SoapException.Actor 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取导致异常的代码段。
public:
property System::String ^ Actor { System::String ^ get(); };
public string Actor { get; }
member this.Actor : string
Public ReadOnly Property Actor As String
属性值
导致异常的代码段。
示例
以下 Web 窗体示例调用 Math
XML Web 服务方法,如果发生除以零,该方法将引发异常。 引发异常时,Web 窗体将捕获异常并将异常详细信息(包括 Actor 和 Code 属性)输出到控件 HtmlTable 中。
<%@ Page Language="C#" %>
<html>
<head>
<script runat=server language="C#">
void Page_Load(Object o, EventArgs e)
{
int UsageCount;
// Create a new instance of the proxy class.
MyMath.Math math = new MyMath.Math();
// Make a call to the Math XML Web service, which throws an exception.
try
{
math.Divide(3, 0);
}
catch (System.Web.Services.Protocols.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));
return;
}
}
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 the cells to the row.
row.Cells.Add(cell1);
cell2.Controls.Add(new LiteralControl(Cell2Text));
// Add the cells 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>
<%@ Page Language="VB"%>
<html>
<head>
<script runat=server language="VB">
Sub Page_Load(o As Object, e As EventArgs)
Dim UsageCount As Integer
' Create a new instance of the proxy class.
Dim math As New MyMath.Math()
' Make a call to the Math XML Web service, which throws an exception.
Try
math.Divide(3, 0)
Catch err As System.Web.Services.Protocols.SoapException
' Populate our Table with the Exception details
ErrorTable.Rows.Add(BuildNewRow("Fault Code Namespace", err.Code.Namespace))
ErrorTable.Rows.Add(BuildNewRow("Fault Code Name", err.Code.Name))
ErrorTable.Rows.Add(BuildNewRow("SOAP Actor that threw Exception", err.Actor))
ErrorTable.Rows.Add(BuildNewRow("Error Message", err.Message))
Return
End Try
End Sub 'Page_Load
Function BuildNewRow(Cell1Text As String, Cell2Text As String) As HtmlTableRow
Dim row As New HtmlTableRow()
Dim cell1 As New HtmlTableCell()
Dim cell2 As New HtmlTableCell()
' Set the contents of the two cells.
cell1.Controls.Add(New LiteralControl(Cell1Text))
' Add the cells to the row.
row.Cells.Add(cell1)
cell2.Controls.Add(New LiteralControl(Cell2Text))
' Add the cells to the row.
row.Cells.Add(cell2)
Return row
End Function 'BuildNewRow
</script>
</head>
<body>
<table id="ErrorTable"
CellPadding=5
CellSpacing=0
Border="1"
BorderColor="black"
runat="server" />
</body>
为了使前面的 Web 窗体使用以下 Math
Web 服务示例,在创建代理类期间指定了 的命名空间 MyMath
。
<%@ WebService Language="C#" Class="Math"%>
using System.Web.Services;
using System;
public class Math : WebService {
[WebMethod]
public float Divide(int dividend, int divisor) {
if (divisor == 0)
throw new DivideByZeroException();
return dividend/divisor;
}
}
<%@ WebService Language="VB" Class="Math"%>
Imports System.Web.Services
Imports System
Public Class Math
Inherits WebService
<WebMethod()> _
Public Function Divide(dividend As Integer, divisor As Integer) As Single
If divisor = 0 Then
Throw New DivideByZeroException()
End If
Return Convert.ToSingle(dividend / divisor)
End Function 'Divide
End Class 'Math
注解
只能 Actor 使用接受参数的构造函数之一 Actor 设置 属性。
发出 SOAP 请求时,会将消息发送给在 SOAP 执行组件属性中指定的收件人。 如果 XML Web 服务中发生异常,则 SOAP 执行组件属性的值将分配给 属性 Actor 。 对于使用 ASP.NET 创建的 XML Web 服务,XML Web 服务方法的 URL 是 SOAP 执行组件属性的值,并在 属性中 Actor 返回。
有关 SOAP 执行组件属性的详细信息,请参阅 SOAP 规范。