방법: XML Serialization을 사용하여 SOAP 메시지 사용자 지정

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

System.Web.Serialization 네임스페이스는 웹 서비스 메서드의 매개 변수 및 반환 값에 적용할 수 있는 XML serialization을 제어하는 다양한 특성을 제공합니다. 이 항목에서는 XmlElementAttribute 특성을 사용하는 방법을 보여 줍니다.

매개 변수를 나타내는 XML 요소의 이름을 지정하려면

  1. 요소 및 네임스페이스(매개 변수 형식이 Literal로 설정된 경우)에 원하는 이름을 지정하는 매개 변수에 XmlElement 특성을 적용합니다. 매개 변수 형식이 Encoded로 설정되어 있으면 매개 변수에 SoapElement 특성을 적용합니다.

    다음 코드 예제에서는 매개 변수를 나타내는 요소 이름이 MyAddressElement, MyZipElementReturnValueElement인 것으로 가정합니다. 또한 반환 값을 나타내는 요소 이름이 ReturnValueElement인 것으로 가정합니다. 샘플의 웹 서비스 메서드 형식은 ASP.NET의 기본값인 Document입니다.

    <%@ WebService Language="C#" Class="SoapDocumentServiceSample" %>
     using System.Web.Services;
     using System.Web.Services.Protocols;
     using System.Xml.Serialization;
    
    [WebService(Namespace="https://www.contoso.com")] 
    public class SoapDocumentServiceSample  
    {
      [ WebMethod ]
      [ return: XmlElement("ReturnValueElement",IsNullable=false)]
      public Address ValidateAddress(
        [XmlElement("MyAddressElement")] Address MyAddress,
        [XmlElement("MyZipElement")] bool useZipPlus4) 
      {
        useZipPlus4 = true;    
        return new Address();
      }
    }
    
    <%@ WebService Language="VB" Class="SoapDocumentServiceSample" %>
     Imports System.Web.Services
     Imports System.Web.Services.Protocols
     Imports System.Xml.Serialization
    
    <WebService(Namespace := "https://www.contoso.com")> _
    Public Class SoapDocumentServiceSample
      < WebMethod > _
      Public Function ValidateAddress( _
           <XmlElement("MyAddressElement")> MyAddress As Address, _
           <XmlElement("MyZipElement")> useZipPlus4 As Boolean)  
           As <XmlElement("ReturnValueElement",IsNullable :=false)> _
           Address 
            useZipPlus4 = True 
         Return new Address()
      End Function
    End Class
    

    웹 서비스에서는 다음 SOAP 요청을 예상합니다. 요소 이름은 매개 변수 이름이 아니라 XmlElement 특성에 지정된 이름과 일치합니다.

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <ValidateAddress xmlns="http://tempuri.org/">
          <MyAddressElement>
            <Street>string</Street>
            <City>string</City>
            <Zip>string</Zip>
          </MyAddressElement>
          <MyZipElement>boolean</MyZipElement>
        </ValidateAddress>
      </soap:Body>
    </soap:Envelope>
    

참고 항목

참조

System.Xml.Serialization Namespace
SoapDocumentMethodAttribute
SoapRpcMethodAttribute
SoapDocumentServiceAttribute
SoapRpcServiceAttribute

개념

SOAP 확장을 사용하는 SOAP 메시지 수정
XML Web services 클라이언트 빌드

기타 리소스

SOAP 메시지 서식 사용자 지정
Introducing XML Serialization
ASP.NET을 사용하는 XML Web services