SoapIncludeAttributeとは? わかりやすく解説

SoapIncludeAttribute クラス

XmlSerializer がオブジェクトをエンコード済みの SOAP XML としてシリアル化または逆シリアル化するときに、型を認識できるようにします。

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct
 Or AttributeTargets.Method Or AttributeTargets.Interface,
 AllowMultiple:=True)> _
Public Class SoapIncludeAttribute
    Inherits Attribute
Dim instance As SoapIncludeAttribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Interface,
 AllowMultiple=true)] 
public class SoapIncludeAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Method|AttributeTargets::Interface,
 AllowMultiple=true)] 
public ref class SoapIncludeAttribute : public
 Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Interface,
 AllowMultiple=true) */ 
public class SoapIncludeAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Method|AttributeTargets.Interface,
 AllowMultiple=true) 
public class SoapIncludeAttribute extends
 Attribute
解説解説

SoapIncludeAttribute クラスは、XmlSerializer がオブジェクトをエンコード済み SOAP XML としてシリアル化または逆シリアル化する方法を制御する一連の属性のうちの 1 つです。結果として生成される XML は、W3C (World Wide Web Consortium) (www.w3.org) のドキュメント『Simple Object Access Protocol (SOAP) 1.1』のセクション 5 に準拠します。類似する属性の完全な一覧については、「エンコード済み SOAP シリアル化を制御する属性」を参照してください。

オブジェクトをエンコード済み SOAP メッセージとしてシリアル化するには、SoapReflectionImporter クラスの ImportTypeMapping メソッドで作成された XmlTypeMapping を使用して、XmlSerializer を構築する必要があります。

SoapIncludeAttribute を適用するときには、派生クラスの Type を指定します。XmlSerializer は、基本クラスと派生クラスの両方を含むオブジェクトをシリアル化する場合は、両方のオブジェクト型を認識できます。

Web サービス記述言語 (WSDL: Web Services Description Language) で記述されたサービスの説明ドキュメントに派生クラスを含める場合は、SoapIncludeAttribute を使用します。たとえば、メソッドが Object を返す場合は、そのメソッドに SoapIncludeAttribute を適用し、実際に返される必要がある型を指定します。

WSDL の詳細については、W3C (World Wide Web Consortium) (www.w3.org) の仕様『Web Services Description Language (WSDL) 1.1』を参照してください。

属性の使用方法については、「属性を使用したメタデータの拡張」を参照してください。

使用例使用例

SoapIncludeAttribute を XML Web サービス メソッドに 2 回適用する例を次に示します。このメソッドは、オブジェクト型 Vehicle (基本クラス) を返します。SoapIncludeAttribute が適用されているため、このメソッドは Vehicle クラスから派生したクラスのインスタンスを返すことができます。

<%@ WebService Language="VB" Class="Test"
 %>
 
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Services.Description
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.Serialization
Imports System.Data
 
Public Class Test : 
Inherits WebService 
   <WebMethod()> Public Function EchoString(
 _
   <XmlElement(DataType:="string")> ByVal
 strval As String) _
   As <XmlElement("MyTime",
 DataType:="time")> DateTime
      Return DateTime.Now
   End Function

 
   <WebMethod(), SoapRpcMethod, SoapInclude(GetType(Car)),
 _
   SoapInclude(GetType(Bike))> _
   Public Function Vehicle (licenseNumber As
 string ) As Vehicle

      If licenseNumber = "0" Then
         Dim v As Vehicle  = new
 Car()
         v.licenseNumber = licenseNumber
         return v

      ElseIf licenseNumber = "1"
 Then
          Dim v As Vehicle  = new
 Bike()
          v.licenseNumber = licenseNumber
          return v
      
      else 
         return Nothing
      End If
   End Function
End Class

<XmlRoot("NewVehicle")> _
public MustInherit Class
 Vehicle 
    public licenseNumber As String
 
    public make As DateTime 
End Class
 
public class Car 
   Inherits Vehicle 
End Class
 
public Class Bike 
   Inherits Vehicle 
End Class
   
<%@ WebService Language="C#" Class="Test" %>
 
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Data;
 
public class Test : WebService {
   [WebMethod()]
   [return:XmlElement("MyTime", DataType="time")]
   public DateTime EchoString([XmlElement(DataType="string")]
 
   string strval) {
        return DateTime.Now;
   }
 
   [WebMethod()]
   [SoapRpcMethod]
   [SoapInclude(typeof(Car)), SoapInclude(typeof(Bike))]
   public Vehicle Vehicle(string licenseNumber)
 {
      if (licenseNumber == "0") {
         Vehicle v = new Car();
         v.licenseNumber = licenseNumber;
         return v;
      }
      else if (licenseNumber == "1")
 {
          Vehicle v = new Bike();
          v.licenseNumber = licenseNumber;
          return v;
      }
      else {
         return null;
      }
   }
}
[XmlRoot("NewVehicle")] 
public abstract class Vehicle {
    public string licenseNumber;
    public DateTime make;
}
 
public class Car : Vehicle {
}
 
public class Bike : Vehicle {
}
   
<%@ WebService Language="VJ#" Class="Test" %>
import System.*;
import System.Web.Services.*;
import System.Web.Services.Protocols.*;
import System.Web.Services.Description.*;
import System.Xml.*;
import System.Xml.Schema.*;
import System.Xml.Serialization.*;
import System.Data.*;

public class Test extends WebService
{
    /** @attribute WebMethod()
     */
    public DateTime EchoString(
        /** @attribute XmlElement(DataType = "string")
         */
        String strval)
    {
        return DateTime.get_Now();
    } //EchoString

    /** @attribute WebMethod()
     */
    /** @attribute SoapRpcMethod()
     */
    /** @attribute SoapInclude(Car.class)
        @attribute SoapInclude(Bike.class)
     */
    public Vehicle Vehicle(String licenseNumber)
    {
        if (licenseNumber.Equals("0")) {
            Vehicle v = new Car();
            v.licenseNumber = licenseNumber;
            return v;
        }
        else {
            if (licenseNumber.Equals("1")) {
                Vehicle v = new Bike();
                v.licenseNumber = licenseNumber;
                return v;
            }
            else {
                return null;
            }
        }
    } //Vehicle
} //Test

/** @attribute XmlRoot("NewVehicle")
 */
abstract public class Vehicle
{
    public String licenseNumber;
    public DateTime make;
} //Vehicle

public class Car extends Vehicle
{
} //Car

public class Bike extends Vehicle
{
} //Bike
継承階層継承階層
System.Object
   System.Attribute
    System.Xml.Serialization.SoapIncludeAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SoapIncludeAttribute メンバ
System.Xml.Serialization 名前空間

SoapIncludeAttribute コンストラクタ

型を指定して、SoapIncludeAttribute クラスの新しいインスタンスを初期化します。

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Dim type As Type

Dim instance As New SoapIncludeAttribute(type)
public SoapIncludeAttribute (
    Type type
)
public:
SoapIncludeAttribute (
    Type^ type
)
public SoapIncludeAttribute (
    Type type
)
public function SoapIncludeAttribute (
    type : Type
)

パラメータ

type

含めるオブジェクトの型。

解説解説
使用例使用例

SoapIncludeAttribute を XML Web サービス メソッドに 2 回適用する例を次に示します。このメソッドは、オブジェクト型 Vehicle (基本クラス) を返します。SoapIncludeAttribute が適用されているため、このメソッドは Vehicle クラスから派生したクラスのインスタンスを返すことができます。

<%@ WebService Language="VB" Class="Test"
 %>
 
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Services.Description
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.Serialization
Imports System.Data
 
Public Class Test : 
Inherits WebService 
   <WebMethod()> Public Function EchoString(
 _
   <XmlElement(DataType:="string")> ByVal
 strval As String) _
   As <XmlElement("MyTime",
 DataType:="time")> DateTime
      Return DateTime.Now
   End Function

 
   <WebMethod(), SoapRpcMethod, SoapInclude(GetType(Car)),
 _
   SoapInclude(GetType(Bike))> _
   Public Function Vehicle (licenseNumber As
 string ) As Vehicle

      If licenseNumber = "0" Then
         Dim v As Vehicle  = new
 Car()
         v.licenseNumber = licenseNumber
         return v

      ElseIf licenseNumber = "1"
 Then
          Dim v As Vehicle  = new
 Bike()
          v.licenseNumber = licenseNumber
          return v
      
      else 
         return Nothing
      End If
   End Function
End Class

<XmlRoot("NewVehicle")> _
public MustInherit Class
 Vehicle 
    public licenseNumber As String
 
    public make As DateTime 
End Class
 
public class Car 
   Inherits Vehicle 
End Class
 
public Class Bike 
   Inherits Vehicle 
End Class
   
<%@ WebService Language="C#" Class="Test" %>
 
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Data;
 
public class Test : WebService {
   [WebMethod()]
   [return:XmlElement("MyTime", DataType="time")]
   public DateTime EchoString([XmlElement(DataType="string")]
 
   string strval) {
        return DateTime.Now;
   }
 
   [WebMethod()]
   [SoapRpcMethod]
   [SoapInclude(typeof(Car)), SoapInclude(typeof(Bike))]
   public Vehicle Vehicle(string licenseNumber)
 {
      if (licenseNumber == "0") {
         Vehicle v = new Car();
         v.licenseNumber = licenseNumber;
         return v;
      }
      else if (licenseNumber == "1")
 {
          Vehicle v = new Bike();
          v.licenseNumber = licenseNumber;
          return v;
      }
      else {
         return null;
      }
   }
}
[XmlRoot("NewVehicle")] 
public abstract class Vehicle {
    public string licenseNumber;
    public DateTime make;
}
 
public class Car : Vehicle {
}
 
public class Bike : Vehicle {
}
   
<%@ WebService Language="VJ#" Class="Test" %>
import System.*;
import System.Web.Services.*;
import System.Web.Services.Protocols.*;
import System.Web.Services.Description.*;
import System.Xml.*;
import System.Xml.Schema.*;
import System.Xml.Serialization.*;
import System.Data.*;

public class Test extends WebService
{
    /** @attribute WebMethod()
     */
    public DateTime EchoString(
        /** @attribute XmlElement(DataType = "string")
         */
        String strval)
    {
        return DateTime.get_Now();
    } //EchoString

    /** @attribute WebMethod()
     */
    /** @attribute SoapRpcMethod()
     */
    /** @attribute SoapInclude(Car.class)
        @attribute SoapInclude(Bike.class)
     */
    public Vehicle Vehicle(String licenseNumber)
    {
        if (licenseNumber.Equals("0")) {
            Vehicle v = new Car();
            v.licenseNumber = licenseNumber;
            return v;
        }
        else {
            if (licenseNumber.Equals("1")) {
                Vehicle v = new Bike();
                v.licenseNumber = licenseNumber;
                return v;
            }
            else {
                return null;
            }
        }
    } //Vehicle
} //Test

/** @attribute XmlRoot("NewVehicle")
 */
abstract public class Vehicle
{
    public String licenseNumber;
    public DateTime make;
} //Vehicle

public class Car extends Vehicle
{
} //Car

public class Bike extends Vehicle
{
} //Bike
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SoapIncludeAttribute クラス
SoapIncludeAttribute メンバ
System.Xml.Serialization 名前空間

SoapIncludeAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。)
参照参照

関連項目

SoapIncludeAttribute クラス
System.Xml.Serialization 名前空間

SoapIncludeAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SoapIncludeAttribute クラス
System.Xml.Serialization 名前空間

SoapIncludeAttribute メンバ

XmlSerializer がオブジェクトをエンコード済みの SOAP XML としてシリアル化または逆シリアル化するときに、型を認識できるようにします。

SoapIncludeAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド SoapIncludeAttribute 型を指定して、SoapIncludeAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SoapIncludeAttribute クラス
System.Xml.Serialization 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「SoapIncludeAttribute」の関連用語

SoapIncludeAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SoapIncludeAttributeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS