SoapException.Code 속성

정의

SOAP fault 코드의 형식을 가져옵니다.

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 fault 코드를 지정하는 XmlQualifiedName입니다.

예제

다음 웹 양식 예제에서는 0으로 나누기 발생 하는 경우 예외를 throw 하는 웹 서비스 메서드를 호출 Math 합니다. 예외가 throw되면 웹 폼은 예외를 catch하고 및 Code 속성을 포함한 Actor 예외 세부 정보를 컨트롤에 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>

앞의 웹 양식에서 다음 Math XML 웹 서비스 예제를 사용하려면 프록시 클래스를 만드는 동안 의 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 새 instance 만들 때만 설정할 수 있습니다.

클래스는 SoapException SOAP를 통해 XML 웹 서비스 메서드를 호출하는 XML 웹 서비스 클라이언트에서 사용합니다. ASP.NET 호출하는 클라이언트가 SOAP를 사용하는지 여부를 처리합니다. XML 웹 서비스에서 예외가 발생하는 경우입니다. 클라이언트가 SOAP를 사용하는 경우 ASP.NET 특정 예외를 로 SoapException 래핑하고 및 Code 속성을 설정합니다Actor.

SOAP 프로토콜 버전 1.1에 대한 SOAP 오류 코드라고 하는 사용 가능한 코드 집합은 다음과 같습니다.

항목 설명
VersionMismatchFaultCode SOAP 봉투의 네임스페이스가 잘못되었습니다.
MustUnderstandFaultCode 모든 SOAP 요소에 처리가 필요한 것은 아닙니다. 그러나 SOAP 요소가 값이 1인 MustUnderstand 특성으로 표시되면 필요합니다. 요소를 처리하지 못하면 이 예외가 생성됩니다.
ClientFaultCode 클라이언트 호출의 형식이 올바르게 지정되지 않았거나 적절한 정보가 포함되지 않았습니다. 예를 들어 클라이언트 호출에 적절한 인증 또는 결제 정보가 없을 수 있습니다. 일반적으로 메시지를 다시 보내기 전에 변경해야 한다는 표시입니다.
ServerFaultCode 서버에서 클라이언트 호출을 처리하는 동안 오류가 발생했습니다. 그러나 메시지 내용으로 인한 문제가 아닙니다. 예를 들어 업스트림 서버가 네트워크 문제로 인해 요청에 응답하지 않을 수 있습니다. 일반적으로 이러한 유형의 예외를 사용하면 클라이언트 호출이 나중에 성공할 수 있습니다. XML 웹 서비스가 예외를 SoapException throw하고 클라이언트가 SOAP를 사용하여 를 호출하는 경우 ASP.NET 예외를 로 SoapException변환하고 속성을 로 ServerFaultCode 설정하고 Code 클라이언트에 다시 throw합니다.

적용 대상

추가 정보