방법: 웹 서비스 메서드에 대한 전체적인 SOAP 본문 형식 제어

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

전체 SOAP 본문 형식 또는 스타일에 대해 WSDL(웹 서비스 기술 언어)은 RPC와 문서의 두 가지 옵션을 제공합니다. .NET Framework는 코드에서 특성을 사용하여 이러한 옵션을 제어합니다.

문서 형식 스타일을 지정하려면

  1. 해당 웹 서비스 메서드를 호출하는 프록시 클래스의 메서드에 SoapDocumentMethod 특성이나 SoapRpcMethod 특성을 적용합니다.

    ASP.NET을 사용하여 만든 웹 서비스에서는 LiteralEncoded 매개 변수 형식 스타일을 지원합니다. 다음 예제에서는 Document 메서드 형식 스타일을 Literal 매개 변수 형식 스타일과 결합합니다.

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

    문서 형식 스타일을 사용하여 SOAP 요청과 SOAP 응답을 모두 정의하는 서비스 설명 내에 XSD 스키마가 정의됩니다. 다음은 DocumentWrappedLiteral 웹 서비스 메서드의 SOAP 요청에 대한 서비스 설명의 일부입니다. DocumentWrappedLiteral 웹 서비스 메서드에 대한 첫 번째 매개 변수는 클래스이고, Literal 매개 변수 형식 스타일이 지정되어 있기 때문에 XSD 스키마가 address 형식에 대해 만들어집니다.

    <s:element name="DocumentWrappedLiteral">
      <s:complexType>
        <s:sequence>
           <s:element minOccurs="1" maxOccurs="1" name="MyAddress"
                      nillable="true" type="s0:Address" /> 
           <s:element minOccurs="1" maxOccurs="1" name="useZipPlus4"
                      type="s:boolean" /> 
        </s:sequence>
      </s:complexType>
    </s:element>
    
    <s:complexType name="Address">
       <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="Street"
                     nillable="true" type="s:string" /> 
          <s:element minOccurs="1" maxOccurs="1" name="City"
                     nillable="true" type="s:string" /> 
          <s:element minOccurs="1" maxOccurs="1" name="Zip" nillable="true"
                     type="s:string" /> 
       </s:sequence>
    </s:complexType>
    

    서비스 설명에 XSD 스키마가 정의되어 있는 경우 DocumentWrappedLiteral 서비스 메서드에 대한 SOAP 요청의 XML 부분은 다음과 같습니다. SOAP 요청에서 Body 요소 아래에 있는 XML 요소는 XSD 스키마에 정의된 요소와 일치합니다.

    <?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>
    

RPC 형식 스타일을 지정하려면

  1. 해당 웹 서비스 메서드를 호출하는 프록시 클래스의 메서드에 SoapRpcMethod 특성을 적용합니다.

    [SoapRpcMethodAttribute("https://www.contoso.com/Rpc",
                            RequestNamespace="https://www.contoso.com",
                            ResponseNamespace="https://www.contoso.com")]
    public Address Rpc(Address address, bool useZipPlus4) {
    
    <SoapRpcMethodAttribute("https://www.contoso.com/Rpc", _
                            RequestNamespace:="https://www.contoso.com", _
                            ResponseNamespace:="https://www.contoso.com")> _
    Public Function Rpc(ByVal address As Address, _
                        ByVal useZipPlus4 As Boolean) As Address
    

    이전 예제에서는 Rpc 메서드에 대한 SOAP 요청 또는 SOAP 응답에 대한 서비스 설명에 XSD 스키마가 엄격하게 정의되어 있지 않고 부분적으로만 설명되어 있습니다. 따라서 Rpc 메서드에 대한 SOAP 요청을 보면 매개 변수가 한 요소의 내부에 캡슐화되고 Encoded 매개 변수 형식을 사용하여 인코딩됩니다.

    <?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:soapenc="https://schemas.xmlsoap.org/soap/encoding/"
                 xmlns:tns="https://www.contoso.com"
                 xmlns:tnsTypes="https://www.contoso.com/encodedTypes"
                 xmlns:wsdl="https://schemas.xmlsoap.org/wsdl/"
                 xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body soap:encodingStyle="https://schemas.xmlsoap.org/soap/encoding/">
        <tns:Rpc>
          <address href="#1" />
          <useZipPlus4>boolean</useZipPlus4>
        </tns:Rpc>
        <tnsTypes:Address id="1">
          <Street id="2">string</Street>
          <City id="3">string</City>
          <Zip id="4">string</Zip>
        </tnsTypes:Address>
      </soap:Body>
    </soap:Envelope> 
    

참고 항목

참조

SoapDocumentMethodAttribute
SoapRpcMethodAttribute

기타 리소스

SOAP 메시지 서식 사용자 지정