[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method)] |
To serialize an object as an encoded SOAP message, you must construct the XmlSerializer using an XmlTypeMapping created with the SoapReflectionImporter.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 (www.w3.org) specification, "Web Services Description Language (WSDL) 1.1".
For more information about using attributes, see the conceptual topic at MSDN: extendingmetadatausingattributes.
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 { }
ctor #1 | Initializes a new instance of the SoapIncludeAttribute class using the specified type. |
Type | Read-write Gets or sets the type of the object that should be used when serializing or deserializing an object. |
TypeId (inherited from System.Attribute) |
Read-only See base class member description: System.Attribute.TypeId When implemented in a derived class, gets a unique identifier for this Attribute. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetHashCode (inherited from System.Attribute) |
See base class member description: System.Attribute.GetHashCode Returns the hash code for this instance. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
IsDefaultAttribute (inherited from System.Attribute) |
See base class member description: System.Attribute.IsDefaultAttribute When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class. |
Match (inherited from System.Attribute) |
See base class member description: System.Attribute.Match When overridden in a derived class, returns a value indicating whether this instance equals a specified object. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public SoapIncludeAttribute( |
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 { }
public Type Type {get; set;}
|
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 { }
public virtual object TypeId {get;}
|
~SoapIncludeAttribute(); |
public override int GetHashCode(); |
public Type GetType(); |
public virtual bool IsDefaultAttribute(); |
The implementation of this method in a derived class compares the value of this instance to a standard, default value obtained by some means, then returns a Boolean value that indicates whether the value of this instance is equal to the standard. The standard value is typically coded as a constant in the implementation, or stored programmatically in a field used by the implementation.
obj
protected object MemberwiseClone(); |
public virtual string ToString(); |