SoapException.Code プロパティ
アセンブリ: System.Web.Services (system.web.services.dll 内)


SoapException クラスの新しいインスタンスを作成している場合だけ、Code プロパティを設定できます。
SoapException クラスは、SOAP 経由で XML Web サービス メソッドを呼び出す XML Web サービス クライアントが使用します。呼び出しを行うクライアントが SOAP を使用するかどうかは、ASP.NET によって処理されます。このとき、XML Web サービスで例外が発生します。クライアントが SOAP を使用している場合、ASP.NET はこの例外を SoapException にラップし、Actor プロパティと Code プロパティを設定します。
SOAP プロトコル Version 1.1 の SOAP 違反コードとして利用できるコードの一覧を次に示します。
項目 | |
---|---|
VersionMismatchFaultCode | |
MustUnderstandFaultCode | 一部の SOAP 要素は処理を省略できます。ただし、値が 1 の MustUnderstand 属性で SOAP 要素がマークされている場合は、その要素を処理する必要があります。要素を処理できなかった場合、この例外が生成されます。 |
ClientFaultCode | クライアントによる呼び出しの書式が正しく設定されていませんでした。またはクライアントによる呼び出しに適切な情報が含まれていませんでした。たとえば、クライアント呼び出しに適切な認証情報または支払い情報が含まれていませんでした。一般的に、この違反コードは、メッセージを再送信する前にその内容を変更する必要があることを示します。 |
ServerFaultCode | クライアントによる呼び出しをサーバーで処理しているときに、メッセージの内容以外の原因によりエラーが発生しました。たとえば、ネットワーク障害のため、アップストリーム サーバーが要求に応答できなかった場合などです。通常、この種類の例外が発生した場合でも、クライアントによる呼び出しは後から成功します。XML Web サービスが SoapException 以外の例外をスローし、クライアントによる呼び出しで SOAP を使用している場合、ASP.NET はこの例外を SoapException に変換し、Code プロパティを ServerFaultCode に設定して、これをクライアントにスローします。 |

0 での除算が発生した場合に例外をスローする Math Web サービス メソッドを呼び出す Web フォームの例を次に示します。例外がスローされると、この Web フォームが例外を受け取り、Actor プロパティおよび Code プロパティを含む例外の詳細を、HtmlTable コントロールに出力します。
<%@ 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>
<%@ 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>
前述の Web フォームで次の Math XML Web サービスを使用するために、MyMath の名前空間がプロキシ クラスの作成中に指定されました。
<%@ 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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SoapException.Code プロパティのページへのリンク