次の方法で共有


方法 : Web サービス全体の既定の SOAP 形式を変更する

この手順では、Web サービス全体の既定の SOAP 形式を変更する方法について説明します。

Web サービス全体の既定のメソッド書式スタイルを設定するには

  • Web サービスを実装するクラスに SoapRpcService 属性または SoapDocumentService 属性を適用します。

    メソッド書式スタイルを Document、既定のパラメータの書式を Literal に設定し、パラメータが単一の要素内にカプセル化される必要があることを指定する例を次に示します。

    <%@ WebService Language="C#" Class="SoapDocumentServiceSample" %>
     using System.Web.Services;
     using System.Web.Services.Protocols;
     using System.Web.Services.Description;
    
    [SoapDocumentService(Use=SoapBindingUse.Literal,
                         ParameterStyle=SoapParameterStyle.Wrapped)]
    [WebService(Namespace="https://www.contoso.com")]
    public class SoapDocumentServiceSample  
    {
        [ WebMethod ]
        public string UseDefaultEncoding(Address MyAddress, 
                                         bool useZipPlus4) 
        {
         return "Use the default encodings for this Web service.";
        }
    }
    
    <%@ WebService Language="VB" Class="SoapDocumentServiceSample" %>
    Imports System.Web.Services
    Imports System.Xml.Serialization
    Imports System.Web.Services.Protocols
    Imports System.Web.Services.Description
    
    < SoapDocumentService(Use := SoapBindingUse.Literal, _
                          ParameterStyle := SoapParameterStyle.Wrapped)> _
    Public Class SoapDocumentServiceSample
      < WebMethod > _
      Public Function UseDefaultEncoding(MyAddress as Address, _
                                         useZipPlus4 As Boolean) As String 
         Return "Use the default formattings for this Web service."
      End Function
    End Class 
    

    UseDefaultEncoding Web サービス メソッドに必要な 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>
        <UseDefaultEncoding xmlns="https://www.contoso.com">
          <MyAddress>
            <Street>string</Street>
            <City>string</City>
            <Zip>string</Zip>
          </MyAddress>
          <useZipPlus4>boolean</useZipPlus4>
        </UseDefaultEncoding>
      </soap:Body>
    </soap:Envelope>
    

関連項目

参照

SoapDocumentServiceAttribute
SoapRpcServiceAttribute

その他の技術情報

SOAP メッセージの書式のカスタマイズ

Footer image

Copyright © 2007 by Microsoft Corporation.All rights reserved.