SoapException.Code プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
SOAP エラー コードの種類を取得します。
public:
property System::Xml::XmlQualifiedName ^ Code { System::Xml::XmlQualifiedName ^ get(); };
public System.Xml.XmlQualifiedName Code { get; }
member this.Code : System.Xml.XmlQualifiedName
Public ReadOnly Property Code As XmlQualifiedName
プロパティ値
発生した SOAP エラー コードを指定する XmlQualifiedName 。
例
次の Web フォームの例では、 Math 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 XML 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
注釈
Code プロパティは、SoapException クラスの新しいインスタンスを作成する場合にのみ設定できます。
SoapException クラスは、SOAP 経由で XML Web サービス メソッドを呼び出す XML Web サービス クライアントで使用されます。 ASP.NET は、呼び出すクライアントが SOAP を使用するかどうかを処理します。 これは、XML Web サービスで例外が発生した場合です。 クライアントが SOAP を使用している場合、ASP.NET は特定の例外を SoapException にラップし、 Actor プロパティと Code プロパティを設定します。
SOAP プロトコル バージョン 1.1 の SOAP エラー コードと呼ばれる使用可能なコードのセットは次のとおりです。
| 品目 | 説明 |
|---|---|
| VersionMismatchFaultCode | SOAP エンベロープの無効な名前空間が見つかりました。 |
| MustUnderstandFaultCode | すべての SOAP 要素で処理が必要なわけではありません。 ただし、SOAP 要素が値 1 の MustUnderstand 属性でマークされている場合は、必須です。 要素を処理しないと、この例外が生成されます。 |
| ClientFaultCode | クライアント呼び出しの形式が正しくないか、適切な情報が含まれていませんでした。 たとえば、クライアント呼び出しに適切な認証または支払い情報がない場合があります。 通常は、メッセージを再送信する前に変更する必要があることを示します。 |
| ServerFaultCode | サーバー上のクライアント呼び出しの処理中にエラーが発生しました。ただし、問題はメッセージの内容が原因ではありません。 たとえば、アップストリーム サーバーがネットワークの問題のために要求に応答しない場合があります。 通常、この種類の例外では、クライアント呼び出しは後で成功する可能性があります。 XML Web サービスが、Code以外の例外をスローし、SOAP を使用してクライアントが呼び出した場合、ASP.NET は例外をSoapExceptionに変換し、Code プロパティをServerFaultCodeに設定してクライアントにスローします。 |