Share via


방법: SOAP 헤더를 처리하는 클라이언트 빌드

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

코드 예제

웹 서비스 클라이언트는 웹 서비스와 통신할 때 SOAP 헤더를 보내고 받을 수 있습니다. Wsdl.exe 유틸리티에서, SOAP 헤더를 예상하거나 반환하는 웹 서비스에 대해 생성한 프록시 클래스는 SOAP 헤더에 대한 정보를 포함합니다. 특히 프록시 클래스에는 웹 서비스에 있는 항목과 연관된 SOAP 헤더를 나타내는 멤버 변수가 있으며, SOAP 헤더를 나타내는 해당 클래스에 대한 정의도 있습니다. 예를 들어, 이전 웹 서비스에 대해 생성된 프록시 클래스에는 MyHeader 형식의 멤버 변수와 MyHeader 클래스에 대한 정의가 포함됩니다. 프록시 클래스 만들기에 대한 자세한 내용은 XML Web services 프록시 만들기를 참조하십시오.

참고: 웹 서비스가 SoapHeader에서 파생된 클래스 대신 SoapHeader 또는 SoapUnknownHeader 형식의 SOAP 헤더를 나타내는 멤버 변수를 정의하는 경우에는 프록시 클래스에 해당 SOAP 헤더에 대한 정보가 포함되지 않습니다.

웹 서비스 클라이언트에서 SOAP 헤더를 처리하려면

  1. SOAP 헤더를 나타내는 클래스의 새 인스턴스를 만듭니다.

    Dim mySoapHeader As MyHeader = New MyHeader()
    
    MyHeader mySoapHeader = new MyHeader();
    
  2. SOAP 헤더에 대한 값을 채웁니다.

    mySoapHeader.Username = UserName
    mySoapHeader.Password = SecurelyStoredPassword
    
    mySoapHeader.Username = Username;
    mySoapHeader.Password = SecurelyStoredPassword
    
  3. 프록시 클래스의 새 인스턴스를 만듭니다.

    Dim proxy As MyWebService = New MyWebService()
    
    MyWebService proxy = new MyWebService();
    
  4. SOAP 헤더를 나타내는 프록시 클래스의 멤버 변수에 SOAP 헤더 개체를 할당합니다.

    proxy.MyHeaderValue = mySoapHeader
    
    proxy.MyHeaderValue = mySoapHeader
    
  5. 웹 서비스 메서드와 통신하는 프록시 클래스의 메서드를 호출합니다.

    웹 서비스에 보낸 SOAP 요청의 SOAP 헤더 부분은 SOAP 헤더 개체에 저장된 데이터 내용을 포함합니다.

    Dim results as String = proxy.MyWebMethod()
    
    string results = proxy.MyWebMethod();
    

예제

다음 코드 예제에서는 SOAP 헤더를 클라이언트에서 웹 서비스로 전달하는 방법을 보여 줍니다.

<%@ Page Language="VB" %>

<asp:Label id="ReturnValue" runat="server" />
<script runat=server language=VB>

 Sub Page_Load(o As Object, e As EventArgs)

  Dim mySoapHeader As MyHeader = New MyHeader()  ' Populate the values of the SOAP header.  mySoapHeader.Username = UserName  mySoapHeader.Password = SecurelyStoredPassword

  ' Create a new instance of the proxy class.
  Dim proxy As MyWebService = New MyWebService()
  
  ' Add the MyHeader SOAP header to the SOAP request.  proxy.MyHeaderValue = mySoapHeader

  ' Call the method on proxy class that communicates with
  ' your Web service method.
  Dim results as String = proxy.MyWebMethod()

  ' Display the results of the method in a label.
  ReturnValue.Text = results

 End Sub
</script>
<%@ Page Language="C#" %>

<asp:Label id="ReturnValue" runat="server" />
<script runat=server language=c#>

 void Page_Load(Object o, EventArgs e)
 {

  MyHeader mySoapHeader = new MyHeader();  // Populate the values of the SOAP header.  mySoapHeader.Username = Username;  mySoapHeader.Password = SecurelyStoredPassword;

  // Create a new instance of the proxy class.
  MyWebService proxy = new MyWebService();
  
  // Add the MyHeader SOAP header to the SOAP request.  proxy.MyHeaderValue = mySoapHeader;

  // Call the method on the proxy class that communicates with
  // your Web service method.
  string results = proxy.MyWebMethod();

  // Display the results of the method in a label.
  ReturnValue.Text = results;
 }
</script>

참고 항목

참조

SoapHeader
SoapUnknownHeader
SoapHeaderException

개념

XML Web services 클라이언트 빌드

기타 리소스

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