This documentation is archived and is not being maintained.

SoapIncludeAttribute Class

Allows the XmlSerializer to recognize a type when it serializes or deserializes an object as encoded SOAP XML.

Namespace: System.Xml.Serialization
Assembly: System.Xml (in 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

/** @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
Not applicable.

The SoapIncludeAttribute class belongs to a family of attributes that controls how the XmlSerializer serializes, or deserializes, an object as encoded SOAP XML. The resulting XML conforms to section 5 of the World Wide Web Consortium ( document, "Simple Object Access Protocol (SOAP) 1.1". For a complete list of similar attributes, see Attributes That Control Encoded SOAP Serialization.

To serialize an object as an encoded SOAP message, you must construct the XmlSerializer using an XmlTypeMapping created with the ImportTypeMapping method of the SoapReflectionImporter class.

When applying the SoapIncludeAttribute, specify the Type of the derived class. When the XmlSerializer serializes objects that include both the base and the derived classes, it can then recognize both object types.

You can use the SoapIncludeAttribute to include derived classes in service description documents that are written in the Web Services Description Language (WSDL). For example, if a method returns an Object, apply the SoapIncludeAttribute to the method and specify the actual types that should be returned.

For more information about WSDL, see World Wide Web Consortium ( specification, "Web Services Description Language (WSDL) 1.1".

For more information about using attributes, see Extending Metadata Using Attributes.

The following example applies the SoapIncludeAttribute twice to an XML Web service method. The method returns an object of type Vehicle (a base class). The SoapIncludeAttribute allows the method to return instances of classes derived from the Vehicle class.

<%@ 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
         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="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


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0