SoapException.Code Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene il tipo di codice di errore 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
Valore della proprietà
Oggetto XmlQualifiedName che specifica il codice di errore SOAP che si è verificato.
Esempio
Nell'esempio di Web Form seguente viene chiamato il Math metodo Servizio Web, che genera un'eccezione se si verifica una divisione per zero. Una volta generata l'eccezione, il Web Form intercetta l'eccezione e restituisce i dettagli dell'eccezione, incluse le Actor proprietà e Code in un HtmlTable controllo .
<%@ 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>
Affinché il Web Form precedente usi l'esempio di servizio Web XML seguente Math , durante la creazione della classe proxy è stato specificato uno spazio dei nomi di 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
Commenti
La Code proprietà può essere impostata solo quando si crea una nuova istanza della SoapException classe .
La SoapException classe è utilizzata dai client del servizio Web XML che chiamano metodi del servizio Web XML su SOAP. ASP.NET gestisce se il client che chiama utilizza SOAP. Si tratta di quando si verifica un'eccezione in un servizio Web XML. Se il client usa SOAP, ASP.NET esegue il wrapping dell'eccezione specifica in un SoapException e imposta le Actor proprietà e Code .
Il set di codici disponibili, noti come codici di errore SOAP per la versione 1.1 del protocollo SOAP, è il seguente:
| Elemento | Descrizione |
|---|---|
| VersionMismatchFaultCode | È stato trovato uno spazio dei nomi non valido per una busta SOAP. |
| MustUnderstandFaultCode | Non tutti gli elementi SOAP richiedono l'elaborazione. Tuttavia, se un elemento SOAP è contrassegnato con l'attributo MustUnderstand con un valore pari a 1, è obbligatorio. L'errore durante l'elaborazione dell'elemento genera questa eccezione. |
| ClientFaultCode | Una chiamata client non è stata formattata correttamente o non contiene le informazioni appropriate. Ad esempio, la chiamata client potrebbe non avere le informazioni di autenticazione o pagamento appropriate. In genere è un'indicazione che il messaggio deve essere modificato prima che venga reinviato. |
| ServerFaultCode | Si è verificato un errore durante l'elaborazione di una chiamata client sul server, ma il problema non è dovuto al contenuto del messaggio. Ad esempio, un server upstream potrebbe non rispondere a una richiesta a causa di problemi di rete. In genere, con questo tipo di eccezione, la chiamata client potrebbe avere esito positivo in un secondo momento. Se un servizio Web XML genera un'eccezione, ad eccezione di SoapException e le chiamate client tramite SOAP, ASP.NET converte l'eccezione in un SoapExceptionoggetto , impostando la Code proprietà su ServerFaultCode e generandola nuovamente al client. |