Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
SoapIncludeAttribute Constructor

SoapIncludeAttribute.SoapIncludeAttribute Constructor

Initializes a new instance of the SoapIncludeAttribute class using the specified type.

Namespace: System.Xml.Serialization
Assembly: System.Xml (in system.xml.dll)

public SoapIncludeAttribute (
	Type type
)
public SoapIncludeAttribute (
	Type type
)
public function SoapIncludeAttribute (
	type : Type
)
Not applicable.

Parameters

type

The type of the object to include.

Apply multiple instances of the SoapIncludeAttribute to a field or property that returns either an array of objects, an ArrayList that contains a collection of objects, or an object that can return multiple types. Set the Type property for each type that you want the field or property to contain.

The following example applies the SoapIncludeAttribute twice to an XML Web services 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="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

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

Community Additions

ADD
Show:
© 2015 Microsoft