Share via


방법: XML Web services 클라이언트에 필요한 SOAP 헤더 처리

이 항목은 레거시 기술과 관련된 것입니다. 이제 XML Web services와 XML Web services 클라이언트는 다음을 사용하여 만들어야 합니다. Windows Communication Foundation.

코드 예제

클라이언트에는 SOAP 헤더의 의미를 올바르게 해석하여 SOAP 요청을 적절하게 처리하는 웹 서비스 메서드가 필요할 수 있습니다. 이를 위해 클라이언트는 SOAP 헤더의 mustUnderstand 특성을 1로 설정합니다. 예를 들어, 다음 SOAP 요청에서는 MyCustomSoapHeader SOAP 헤더를 처리할 SOAP 요청 수신자가 필요합니다.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/" >
  <soap:Header>
    <MyCustomSoapHeader soap:mustUnderstand="1" xmlns="https://www.contoso.com">
      <custom>Keith</custom>
    </MyCustomSoapHeader>
  </soap:Header>
  <soap:Body>
    <MyUnknownHeaders xmlns="https://www.contoso.com" />
  </soap:Body>
</soap:Envelope>

웹 서비스에서 SOAP 헤더를 정의하는지 여부에 따라 웹 서비스에서 클라이언트에 필요한 SOAP 헤더를 처리하는 방법이 결정됩니다. ASP.NET은 웹 서비스에서 SOAP 헤더를 정의할 경우 많은 작업을 처리합니다. 다음 절차에서는 두 가지 경우의 처리 방법을 보여 줍니다.

웹 서비스에 정의되어 있지 않지만 웹 서비스 클라이언트에 필요한 SOAP 헤더를 처리하려면

  1. 웹 서비스 클라이언트에서 알 수 없는 SOAP 헤더를 처리하려면 다음 단계를 수행합니다. 이 경우 SOAP 헤더의 DidUnderstand 속성에 특별히 유의해야 합니다.

    웹 서비스에 정의되지 않은 SOAP 헤더의 경우 DidUnderstand의 초기 값이 false입니다. 웹 서비스 메서드가 반환된 후에 ASP.NET에서 DidUnderstand 속성이 false로 설정된 SOAP 헤더를 감지하면 SoapHeaderException이 자동으로 throw됩니다.

웹 서비스 클라이언트에 필요하며 웹 서비스에 정의되어 있는 SOAP 헤더를 처리하려면

  1. 각 웹 서비스 메서드에서 ASP.NET을 사용하여 만든 웹 서비스의 SOAP 헤더를 처리하려면 다음 단계를 수행합니다.

    웹 서비스에 정의되어 있고 SOAP 헤더를 수신하는 웹 서비스 메서드에서 처리되는 SOAP 헤더의 경우 ASP.NET에서는 웹 서비스가 SOAP 헤더를 알고 있고 DidUnderstand의 초기 값이 true로 설정되어 있다고 간주합니다.

예제

다음 MyWebService 웹 서비스는 MyHeader SOAP 헤더를 정의하여 MyWebMethod 웹 서비스 메서드로 호출과 함께 보냅니다. 또한 MyWebMethod는 알 수 없는 모든 SOAP 헤더를 처리합니다. MyWebMethod에서 처리할 수 있는 SOAP 헤더의 경우 DidUnderstandtrue로 설정됩니다.

<%@ WebService Language="C#" Class="MyWebService" %>
using System.Web.Services;
using System.Web.Services.Protocols;

// Define a SOAP header by deriving from the SoapHeader base class.
public class MyHeader : SoapHeader {
    public string MyValue;
}
public class MyWebService {
    public MyHeader myHeader;

    // Receive all SOAP headers other than the MyHeader SOAP header.
    public SoapUnknownHeader[] unknownHeaders;
 
    [WebMethod]
    [SoapHeader("myHeader")]
    //Receive any SOAP headers other than MyHeader.
    [SoapHeader("unknownHeaders")]
    public string MyWebMethod() 
    {
       foreach (SoapUnknownHeader header in unknownHeaders) 
       {
         // Perform some processing on the header.
         if (header.Element.Name == "MyKnownHeader")
               header.DidUnderstand = true;
         else
                // For those headers that cannot be 
                // processed, set DidUnderstand to false.
                header.DidUnderstand = false;
       }
       return "Hello";
    }
}
<%@ WebService Language="VB" Class="MyWebService" %>
Imports System.Web.Services
Imports System.Web.Services.Protocols

' Define a SOAP header by deriving from the SoapHeader base class.
Public Class MyHeader : Inherits SoapHeader
    Public MyValue As String
End Class

Public Class MyWebService
    Public myHeader As MyHeader
    
    ' Receive all SOAP headers other than the MyHeader SOAP header.
    Public unknownHeaders() As SoapUnknownHeader    
    
    <WebMethod, _
     SoapHeader("myHeader"), _
     SoapHeader("unknownHeaders")> _
    Public Function MyWebMethod() As String
        'Receive any SOAP headers other than MyHeader.
        Dim header As SoapUnknownHeader        For Each header In unknownHeaders
            ' Perform some processing on the header.
            If header.Element.Name = "MyKnownHeader" Then
                header.DidUnderstand = True
            ' For those headers that cannot be 
            ' processed, set DidUnderstand to false.
            Else
                header.DidUnderstand = False
            End If
        Next header
        Return "Hello"
    End Function
End Class
y4t36w86.note(ko-kr,VS.100).gif참고:
DidUnderstand 속성은 ASP.NET에서 웹 서비스 메서드와 통신하는 데 사용됩니다. 이 속성은 SOAP 사양에 포함되지 않으므로 속성 값이 SOAP 요청 또는 SOAP 응답에 표시되지 않습니다.

y4t36w86.note(ko-kr,VS.100).gif참고:
웹 서비스에서 SOAP 헤더를 전달하는 경우 SOAP 사양의 규칙 특히, Actor 값에 속하는 규칙을 따라야 합니다. 자세한 내용은 W3C 웹 사이트(http://www.w3.org/TR/SOAP/)를 참조하십시오.

참고 항목

참조

SoapHeader
SoapHeaderAttribute
SoapUnknownHeader
SoapHeaderException

개념

XML Web services 클라이언트 빌드

기타 리소스

SOAP 헤더 사용
ASP.NET을 사용하는 XML Web services