방법: 웹 서비스 메서드 매개 변수가 추가 요소에 인코딩되는지 여부 제어

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

웹 서비스 메서드의 매개 변수 또는 반환 값은 SOAP 메시지의 Body 요소 내의 부모 XML 요소에 자동으로 캡슐화되거나, WSDL(웹 서비스 기술 언어) 문서에서 메시지 part 요소에 직접 바인딩될 수 있습니다. .NET Framework는 이러한 두 옵션을 wrapped와 bare로 각각 지칭하며 속성을 사용하여 제어합니다.

하나의 XML 요소에서 매개 변수를 캡슐화하도록 지정하려면

  1. ParameterStyle 속성을 Wrapped로 설정하여 해당 웹 서비스 메서드를 호출하는 프록시 클래스 내의 메서드에 SoapDocumentMethod 특성을 적용합니다.

    다음 코드 예제에서는 ParameterStyleWrapped로 설정합니다. 또한 매개 변수 형식 스타일을 Literal로 설정합니다.

    [SoapDocumentMethod("https://www.contoso.com/DocumentWrappedLiteral",
                        RequestNamespace="https://www.contoso.com",
                        ResponseNamespace="https://www.contoso.com", 
                        Use=SoapBindingUse.Literal, 
                        ParameterStyle=SoapParameterStyle.Wrapped)]
    public string DocumentWrappedLiteral(Address1 address, 
                                         bool useZipPlus4) {
    
    <SoapDocumentMethod("https://www.contoso.com/DocumentWrappedLiteral", _
                        RequestNamespace:="https://www.contoso.com", _
                        ResponseNamespace:="https://www.contoso.com", _
                        Use:=SoapBindingUse.Literal, _
                        ParameterStyle:=SoapParameterStyle.Wrapped)> _
    Public Function DocumentWrappedLiteral(ByVal address As Address1, _
                                 ByVal useZipPlus4 As Boolean) As String
    

    SOAP 요청의 XML 부분은 기본적으로 웹 서비스 메서드 뒤에 명명된 요소의 매개 변수를 캡슐화합니다.

    <?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>
        <DocumentWrappedLiteral xmlns="https://www.contoso.com">
          <MyAddress>
            <Street>string</Street>
            <City>string</City>
            <Zip>string</Zip>
          </MyAddress>
          <useZipPlus4>boolean</useZipPlus4>
        </DocumentWrappedLiteral>
      </soap:Body>
    </soap:Envelope>
    

    SOAP 응답의 XML 부분은 요소 내의 결과를 포함하여 웹 서비스 메서드에 대한 out 매개 변수를 캡슐화합니다. 캡슐화하는 요소의 이름은 기본적으로 웹 서비스 메서드의 이름에 Response를 추가하여 지정됩니다.

    <?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>
        <DocumentWrappedLiteralResponse xmlns="https://www.contoso.com">
          <DocumentWrappedLiteralResult>string
          </DocumentWrappedLiteralResult>
        </DocumentWrappedLiteralResponse>
      </soap:Body>
    </soap:Envelope>
    

매개 변수가 Body 요소 바로 뒤에 오도록 지정하려면

  1. ParameterStyle 속성을 Bare로 설정하여 해당 웹 서비스 메서드를 호출하는 프록시 클래스 내의 메서드에 SoapDocumentMethod 특성을 적용합니다.

    Wsdl.exe에서 생성되는 다음 예제에서는 ParameterStyleBare로 설정하고 매개 변수 형식 스타일을 Literal로 설정합니다. 모든 매개 변수를 캡슐화하는 요소에는 네임스페이스를 지정할 수 없기 때문에 매개 변수 및 반환 값에 대해 개별적으로 네임스페이스를 지정해야 합니다. 각 매개 변수 및 반환 값에 XmlElementAttribute를 적용하고, Namespace 속성을 설정하여 이 작업을 수행할 수 있습니다.

    [SoapDocumentMethod(
         "https://www.contoso.com/DocumentBareLiteral",
         Use=SoapBindingUse.Literal,
         ParameterStyle=SoapParameterStyle.Bare)]
    [return: XmlElement(Namespace="https://www.contoso.com",                    IsNullable=true)]
    public string DocumentBareLiteral(
       [XmlElement(Namespace="https://www.contoso.com",
                         IsNullable=true)] 
       Address1 MyAddress, 
       [XmlElement(Namespace="https://www.contoso.com",
                IsNullable=false)] 
       bool useZipPlus4) {
    
    <SoapDocumentMethod( _
         https://www.contoso.com/DocumentBareLiteral", _
         Use:=SoapBindingUse.Literal, _
         ParameterStyle:= SoapParameterStyle.Bare)> _
    Public Function DocumentBareLiteral( _
       ByVal <XmlElement([Namespace]:="https://www.contoso.com", _
                          IsNullable:=true)> _
       MyAddress As Address1, _
       ByVal <XmlElement([Namespace]:="https://www.contoso.com", _
                          IsNullable:=false)> _
       useZipPlus4 As Boolean) _
       As <XmlElement([Namespace]:="https://www.contoso.com", _
                      IsNullable:=true)> _
       String
    

    SOAP 요청에서 매개 변수가 매핑되는 XML 요소는 Body 요소 바로 뒤에 오며 네임스페이스가 개별적으로 지정됩니다.

    <?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>
        <MyAddress xmlns="https://www.contoso.com">
          <Street>string</Street>
          <City>string</City>
          <Zip>string</Zip>
        </MyAddress>
        <useZipPlus4 xmlns="https://www.contoso.com">boolean</useZipPlus4>
      </soap:Body>
    </soap:Envelope>
    

    반환 값을 포함하여 out 매개 변수는 SOAP 응답에서 Body 요소 뒤에 오는 XML 요소에 매핑됩니다. 반환 값 요소 이름은 기본적으로 웹 서비스 메서드 이름에 Result 접미사를 붙여 지정됩니다.

    <?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>
        <DocumentBareLiteralResult xmlns="https://www.contoso.com">
           string</DocumentBareLiteralResult>
      </soap:Body>
    </soap:Envelope>
    

참고 항목

참조

SoapDocumentMethodAttribute
SoapRpcMethodAttribute

기타 리소스

SOAP 메시지 서식 사용자 지정