.NET Framework Class Library
SoapAttributeAttribute Class

Specifies that the XmlSerializer must serialize the class member as an encoded SOAP attribute.

Inheritance Hierarchy
SystemObject
   SystemAttribute
    System.Xml.SerializationSoapAttributeAttribute

Namespace:   System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)
Syntax
<[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_0_0_0%]([%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_0_0_1%].Property Or [%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_0_0_2%].Field Or [%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_0_0_3%].Parameter Or [%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_0_0_4%].ReturnValue)> _
Public Class SoapAttributeAttribute _
	Inherits [%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_0_0_5%]
[[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_1_0_0%]([%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_1_0_1%].Property|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_1_0_2%].Field|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_1_0_3%].Parameter|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_1_0_4%].ReturnValue)]
public class SoapAttributeAttribute : [%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_1_0_5%]
[[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_2_0_0%]([%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_2_0_1%]::Property|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_2_0_2%]::Field|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_2_0_3%]::Parameter|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_2_0_4%]::ReturnValue)]
public ref class SoapAttributeAttribute : public [%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_2_0_5%]
[<[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_3_0_0%]([%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_3_0_1%].Property|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_3_0_2%].Field|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_3_0_3%].Parameter|[%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_3_0_4%].ReturnValue)>]
type SoapAttributeAttribute =  
    class 
        inherit [%$TOPIC/9zfkzbe0_en-us_VS_110_3_0_3_0_5%] 
    end

The SoapAttributeAttribute type exposes the following members.

Constructors
  NameDescription
Public method Supported by the XNA Framework SoapAttributeAttributeInitializes a new instance of the SoapAttributeAttribute class.
Public method Supported by the XNA Framework SoapAttributeAttribute(String)Initializes a new instance of the SoapAttributeAttribute class using the specified value as the name of the XML attribute.
Top
Properties
  NameDescription
Public property Supported by the XNA Framework AttributeNameGets or sets the name of the XML attribute generated by the XmlSerializer.
Public property Supported by the XNA Framework DataTypeGets or sets the XML Schema definition language (XSD) data type of the SOAP attribute generated by the XmlSerializer.
Public property Supported by the XNA Framework NamespaceGets or sets the XML namespace of the XML attribute.
Public property TypeIdWhen implemented in a derived class, gets a unique identifier for this Attribute. (Inherited from Attribute.)
Top
Methods
  NameDescription
Public method Supported by the XNA Framework EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected method Supported by the XNA Framework FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by the XNA Framework GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public method Supported by the XNA Framework GetTypeGets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttributeWhen overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method Supported by the XNA Framework MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected method Supported by the XNA Framework MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by the XNA Framework ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Explicit Interface Implementations
  NameDescription
Explicit interface implemetation Private method _AttributeGetIDsOfNamesMaps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoRetrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeGetTypeInfoCountRetrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetation Private method _AttributeInvokeProvides access to properties and methods exposed by an object. (Inherited from Attribute.)
Top
Remarks

The SoapAttributeAttribute 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 (www.w3.org) 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.

Apply the SoapAttributeAttribute to a public field to specify that the XmlSerializer serializes the field as an XML attribute. You can specify an alternative name of the attribute by setting the AttributeName property. Set the DataType if the attribute must be given a specific XML Schema definition language (XSD) data type. If the attribute belongs to a specific XML namespace, set the Namespace property.

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

NoteNote

You can use the word SoapAttribute in your code instead of the longer SoapAttributeAttribute.

Examples

The following example serializes a class that contains several fields to which a SoapAttributeAttribute is applied.

Imports System
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Xml.Serialization
Imports System.Xml.Schema

<SoapInclude(GetType(Vehicle))> _
Public Class Group

   <SoapAttribute (Namespace:= "http:'www.cpandl.com")> _
   Public GroupName As String    
   <SoapAttribute(DataType:= "base64Binary")> _
   Public GroupNumber() As   Byte 

   <SoapAttribute(DataType:= "date", AttributeName:= "CreationDate")> _
   Public Today As DateTime 
   <SoapElement(DataType:= "nonNegativeInteger", _
   ElementName:= "PosInt")> _
   Public PostitiveInt As String  

   Public GroupVehicle As Vehicle 
End Class 

Public Class Vehicle
   Public licenseNumber As String  
End Class 

Public Class Run

   Shared Sub Main()

      Dim test As Run = New Run()
      test.SerializeObject("SoapAtts.xml")
      test.DeserializeObject("SoapAtts.xml")
   End Sub 

   Public Sub SerializeObject(filename As String)

      ' Create an instance of the XmlSerializer Class that 
      ' can generate encoded SOAP messages. 
      Dim mySerializer As XmlSerializer  =  ReturnSOAPSerializer()

      Dim myGroup As Group = MakeGroup()
      ' Writing the file requires a TextWriter. 
      Dim writer As XmlTextWriter = _
      New XmlTextWriter(filename, Encoding.UTF8)
      writer.Formatting = Formatting.Indented
      writer.WriteStartElement("wrapper")
      ' Serialize the Class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup)
      writer.WriteEndElement()
      writer.Close()
   End Sub 

   Private Function MakeGroup() As Group 
      ' Create an instance of the Class that will be serialized. 
      Dim myGroup As Group = New Group()

      ' Set the object properties.
      myGroup.GroupName = ".NET" 

      Dim hexByte() As Byte= New Byte(1){Convert.ToByte(100), _
      Convert.ToByte(50)}
      myGroup.GroupNumber = hexByte

      Dim myDate As DateTime = New DateTime(2002,5,2)
      myGroup.Today = myDate
      myGroup.PostitiveInt= "10000"
      myGroup.GroupVehicle = New Vehicle()
      myGroup.GroupVehicle.licenseNumber="1234"
      return myGroup
   End Function    	

   Public Sub DeserializeObject(filename As String)
      ' Create an instance of the XmlSerializer Class that 
      ' can generate encoded SOAP messages. 
      Dim mySerializer As XmlSerializer =  ReturnSOAPSerializer()

      ' Reading the file requires an  XmlTextReader. 
      Dim reader As XmlTextReader = _
      New XmlTextReader(filename)
      reader.ReadStartElement("wrapper")

      ' Deserialize and cast the object. 
      Dim myGroup As Group 
      myGroup = _
      CType(mySerializer.Deserialize(reader), Group)
      reader.ReadEndElement()
      reader.Close()

   End Sub

   private Function ReturnSOAPSerializer() As XmlSerializer 
      ' Create an instance of the XmlSerializer Class. 
      Dim myMapping As XmlTypeMapping = _
      (New SoapReflectionImporter().ImportTypeMapping _
      (GetType(Group)))
       return New XmlSerializer(myMapping)
   End Function 
End Class
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Schema;

[SoapInclude(typeof(Vehicle))]
public class Group
{
   [SoapAttribute (Namespace = "http://www.cpandl.com")]
   public string GroupName;

   [SoapAttribute(DataType = "base64Binary")]
   public Byte [] GroupNumber;

   [SoapAttribute(DataType = "date", AttributeName = "CreationDate")]
   public DateTime Today;
   [SoapElement(DataType = "nonNegativeInteger", ElementName = "PosInt")]
   public string PostitiveInt;

   public Vehicle GroupVehicle;
}

public class Vehicle
{
   public string licenseNumber;
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();
      test.SerializeObject("SoapAtts.xml");
      test.DeserializeObject("SoapAtts.xml");
   }
   public void SerializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class that 
      // can generate encoded SOAP messages.
      XmlSerializer mySerializer =  ReturnSOAPSerializer();

      Group myGroup=MakeGroup();
      // Writing the file requires a TextWriter.
      XmlTextWriter writer = 
      new XmlTextWriter(filename, Encoding.UTF8);
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("wrapper");
      // Serialize the class, and close the TextWriter.
      mySerializer.Serialize(writer, myGroup);
      writer.WriteEndElement();
      writer.Close();
   }

   private Group MakeGroup(){
      // Create an instance of the class that will be serialized.
      Group myGroup = new Group();

      // Set the object properties.
      myGroup.GroupName = ".NET";

      Byte [] hexByte = new Byte[2]{Convert.ToByte(100),
      Convert.ToByte(50)};
      myGroup.GroupNumber = hexByte;

      DateTime myDate = new DateTime(2002,5,2);
      myGroup.Today = myDate;
      myGroup.PostitiveInt= "10000";
      myGroup.GroupVehicle = new Vehicle();
      myGroup.GroupVehicle.licenseNumber="1234";
      return myGroup;
   }   	

   public void DeserializeObject(string filename)
   {
      // Create an instance of the XmlSerializer class that 
      // can generate encoded SOAP messages.
      XmlSerializer mySerializer =  ReturnSOAPSerializer();

      // Reading the file requires an  XmlTextReader.
      XmlTextReader reader= 
      new XmlTextReader(filename);
      reader.ReadStartElement("wrapper");

      // Deserialize and cast the object.
      Group myGroup; 
      myGroup = (Group) mySerializer.Deserialize(reader);
      reader.ReadEndElement();
      reader.Close();

   }

   private XmlSerializer ReturnSOAPSerializer(){
      // Create an instance of the XmlSerializer class.
      XmlTypeMapping myMapping = 
      (new SoapReflectionImporter().ImportTypeMapping
      (typeof(Group)));
       return new XmlSerializer(myMapping);
   }
}
#using <System.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Text;
using namespace System::Xml;
using namespace System::Xml::Serialization;
using namespace System::Xml::Schema;

//using namespace System::Runtime::Remoting::Metadata; 
public ref class Vehicle
{
public:
   String^ licenseNumber;
};


[SoapInclude(Vehicle::typeid)]
public ref class Group
{
public:

   [SoapAttributeAttribute(Namespace="http://www.cpandl.com")]
   String^ GroupName;

   [SoapAttributeAttribute(DataType="base64Binary")]
   array<Byte>^GroupNumber;

   [SoapAttributeAttribute(DataType="date",AttributeName="CreationDate")]
   DateTime Today;

   [SoapElement(DataType="nonNegativeInteger",ElementName="PosInt")]
   String^ PostitiveInt;
   Vehicle^ GroupVehicle;
};

public ref class Run
{
public:
   void SerializeObject( String^ filename )
   {
      // Create an instance of the XmlSerializer class that 
      // can generate encoded SOAP messages.
      XmlSerializer^ mySerializer = ReturnSOAPSerializer();
      Group^ myGroup = MakeGroup();

      // Writing the file requires a TextWriter.
      XmlTextWriter^ writer = gcnew XmlTextWriter( filename,Encoding::UTF8 );
      writer->Formatting = Formatting::Indented;
      writer->WriteStartElement( "wrapper" );

      // Serialize the class, and close the TextWriter.
      mySerializer->Serialize( writer, myGroup );
      writer->WriteEndElement();
      writer->Close();
   }


private:
   Group^ MakeGroup()
   {
      // Create an instance of the class that will be serialized.
      Group^ myGroup = gcnew Group;

      // Set the Object* properties.
      myGroup->GroupName = ".NET";
      array<Byte>^hexByte = {Convert::ToByte( 100 ),Convert::ToByte( 50 )};
      myGroup->GroupNumber = hexByte;
      DateTime myDate = DateTime(2002,5,2);
      myGroup->Today = myDate;
      myGroup->PostitiveInt = "10000";
      myGroup->GroupVehicle = gcnew Vehicle;
      myGroup->GroupVehicle->licenseNumber = "1234";
      return myGroup;
   }

public:
   void DeserializeObject( String^ filename )
   {
      // Create an instance of the XmlSerializer class that 
      // can generate encoded SOAP messages.
      XmlSerializer^ mySerializer = ReturnSOAPSerializer();

      // Reading the file requires an  XmlTextReader.
      XmlTextReader^ reader = gcnew XmlTextReader( filename );
      reader->ReadStartElement( "wrapper" );

      // Deserialize and cast the Object*.
      Group^ myGroup;
      myGroup = safe_cast<Group^>(mySerializer->Deserialize( reader ));
      reader->ReadEndElement();
      reader->Close();
   }

private:
   XmlSerializer^ ReturnSOAPSerializer()
   {

      // Create an instance of the XmlSerializer class.
      XmlTypeMapping^ myMapping = (gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid );
      return gcnew XmlSerializer( myMapping );
   }
};

int main()
{
   Run^ test = gcnew Run;
   test->SerializeObject( "SoapAtts.xml" );
   test->DeserializeObject( "SoapAtts.xml" );
}
Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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