다음을 통해 공유


방법: 웹 서비스 메서드에 대한 매개 변수 및 반환 값 형식 제어

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

메서드 매개 변수와 반환 값 또는 use에 해당하는 XML 요소의 형식을 위해 WSDL(웹 서비스 기술 언어)은 SOAP encoded와 literal의 두 가지 옵션을 제공합니다. .NET Framework는 코드에서 특성을 사용하여 이러한 옵션을 제어합니다. ASP.NET에서 XML 형식 지정 방법을 제어하기 위해 확장 아키텍처를 제공하긴 하지만, 매개 변수가 serialize되는 순서는 보장되지 않습니다.

Literal 매개 변수의 형식을 지정하려면

  1. Use 속성을 SoapBindingUse.Literal로 설정하여 SoapDocumentMethod 특성을 프록시 클래스의 메서드에 적용합니다.

    SoapBindingUse 열거형은 ASP.NET을 사용하여 만든 웹 서비스에서 사용할 수 있는 매개 변수 형식 스타일을 지정합니다.

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

    DocumentLiteral 웹 서비스 메서드에 대한 SOAP 요청의 XML 부분은 다음과 같습니다. 이 매개 변수는 Body 요소 내에 있고 XSD 스키마라고 하는 자체 포함된 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>
        <DocumentLiteral xmlns="https://www.contoso.com">
          <address>
            <Street>One Microsoft Way</Street>
            <City>Redmond</City>
            <Zip>98052</Zip>
          </address>
          <useZipPlus4>True</useZipPlus4>
        </DocumentLiteral>
      </soap:Body>
    </soap:Envelope>
    

Encoded 매개 변수의 형식을 지정하려면

  1. Use 속성을 SoapBindingUse.Encoded로 설정하여 SoapDocumentMethod 특성 또는 SoapRpcMethod 특성을 프록시 클래스의 메서드에 적용합니다.

    Literal 매개 변수 형식 스타일과 달리 Encoded 매개 변수 형식 스타일은 모든 웹 서비스 메서드 형식 스타일과 함께 사용할 수 있습니다. 웹 서비스 메서드 형식 스타일에 대한 자세한 내용은 SOAP 형식에 대한 .NET Framework 지원을 참조하십시오.

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

    DocumentEncoded 서비스 메서드에 대한 SOAP 요청의 XML 부분은 다음과 같습니다. 이 매개 변수는 SOAP 사양의 Section 5에 요약된 인코딩 규칙을 사용하여 형식이 지정되기 때문에 Literal 형식 스타일과 완전히 다르게 표시되는 것을 볼 수 있습니다. address 매개 변수는 단순 데이터 형식이 아니므로 특히 주의하십시오.

    <?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/">
        <tnsTypes:DocumentEncoded>
          <address href="#1" />
          <useZipPlus4>boolean</useZipPlus4>
        </tnsTypes:DocumentEncoded>
        <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 메시지 서식 사용자 지정