SoapException.Code Özellik

Tanım

SOAP hata kodunun türünü alır.

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

Özellik Değeri

Oluşan XmlQualifiedName SOAP hata kodunu belirten bir.

Örnekler

Aşağıdaki Web Formu örneği, sıfıra Math bölme gerçekleşirse özel durum oluşturan Web Hizmeti yöntemini çağırır. Özel durum oluşturulduktan sonra, Web Formu özel durumu yakalar ve ve Code özellikleri de dahil olmak üzere Actor özel durum ayrıntılarını bir HtmlTable denetime verir.

<%@ 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>

Yukarıdaki Web Formunun aşağıdaki Math XML Web hizmeti örneğini kullanması için ara sunucu sınıfı oluşturulurken ad alanı MyMath belirtildi.

<%@ 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

Açıklamalar

Code özelliği yalnızca sınıfın SoapException yeni bir örneği oluşturulurken ayarlanabilir.

SoapException sınıfı, SOAP üzerinden XML Web hizmeti yöntemlerini çağıran XML Web hizmeti istemcileri tarafından kullanılır. ASP.NET çağıran istemcinin SOAP kullanıp kullanmadığını işler. Bu, XML Web hizmetinde bir özel durum oluştuğu durumdur. İstemci SOAP kullanıyorsa, ASP.NET belirli bir özel durumu içine SoapException sarmalar ve ve Code özelliklerini ayarlarActor.

SOAP protokolü sürüm 1.1 için SOAP Hata Kodları olarak bilinen kullanılabilir kodlar kümesi şunlardır:

Öğe Açıklama
VersionMismatchFaultCode SOAP zarfı için geçersiz bir ad alanı bulundu.
MustUnderstandFaultCode Tüm SOAP öğeleri işleme gerektirmez. Ancak, bir SOAP öğesi özniteliğiyle 1 değeriyle MustUnderstand işaretlenmişse, bu gereklidir. öğesinin işlenememesi bu özel durumu oluşturur.
ClientFaultCode İstemci çağrısı doğru biçimlendirilmedi veya uygun bilgileri içermiyordu. Örneğin, istemci çağrısı doğru kimlik doğrulamasına veya ödeme bilgilerine sahip olmayabilir. Genellikle iletinin yeniden gönderilmeden önce değiştirilmesi gerektiğinin göstergesidir.
ServerFaultCode Sunucudaki bir istemci çağrısı işlenirken bir hata oluştu, ancak sorun ileti içeriğinden kaynaklanmaz. Örneğin, bir yukarı akış sunucusu ağ sorunları nedeniyle bir isteğe yanıt vermeyebilir. Genellikle, bu tür bir özel durumla istemci çağrısı daha sonra başarılı olabilir. XML Web hizmeti dışında bir özel durum SoapException oluşturursa ve istemci SOAP kullanarak çağırırsa, ASP.NET özel durumu olarak SoapExceptionayarlar CodeServerFaultCode ve istemciye geri atar.

Şunlara uygulanır

Ayrıca bkz.