SoapTypeAttribute Class
Controls the schema generated by the XmlSerializer when a class instance is serialized as SOAP encoded XML.
Assembly: System.Xml (in System.Xml.dll)
| Name | Description | |
|---|---|---|
![]() | SoapTypeAttribute() | Initializes a new instance of the SoapTypeAttribute class. |
![]() | SoapTypeAttribute(String^) | Initializes a new instance of the SoapTypeAttribute class and specifies the name of the XML type. |
![]() | SoapTypeAttribute(String^, String^) | Initializes a new instance of the SoapTypeAttribute class and specifies the name and XML namespace of the type. |
| Name | Description | |
|---|---|---|
![]() | IncludeInSchema | Gets or sets a value that indicates whether to include the type in SOAP-encoded XML Schema documents. |
![]() | Namespace | Gets or sets the namespace of the XML type. |
![]() | TypeId | |
![]() | TypeName | Gets or sets the name of the XML type. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | This API supports the product infrastructure and is not intended to be used directly from your code. Returns a value that indicates whether this instance is equal to a specified object.(Inherited from Attribute.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Returns the hash code for this instance.(Inherited from Attribute.) |
![]() | GetType() | |
![]() | IsDefaultAttribute() | When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.(Inherited from Attribute.) |
![]() | Match(Object^) | When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.) |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | _Attribute::GetIDsOfNames(Guid%, IntPtr, UInt32, UInt32, IntPtr) | Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.) |
![]() ![]() | _Attribute::GetTypeInfo(UInt32, UInt32, IntPtr) | Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.) |
![]() ![]() | _Attribute::GetTypeInfoCount(UInt32%) | Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.) |
![]() ![]() | _Attribute::Invoke(UInt32, Guid%, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | Provides access to properties and methods exposed by an object.(Inherited from Attribute.) |
The SoapTypeAttribute 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, construct the XmlSerializer using an XmlTypeMapping created with the ImportTypeMapping method of the SoapReflectionImporter class.
The SoapTypeAttribute can only be applied to class declarations.
The IncludeInSchema property determines whether the resulting XML element type is included in the XML Schema document (.xsd) for the generated XML stream. To see the schema, compile the class into a DLL file. Pass the resulting file as an argument to the XML Schema Definition Tool (Xsd.exe). The tool generates the XML Schema for the XML stream generated when the class is serialized by an instance of the XmlSerializer class.
Setting a different namespace causes Xsd.exe to write a different schema (.xsd) file for the XML stream generated when the class is serialized.
The following example serializes a class named Group. The SoapTypeAttribute is applied to the class, with the TypeName set to "SoapGroupType". The SoapTypeAttribute is also overridden, changing the TypeName to "Team". Both versions are serialized, resulting in two files: SoapType.xml and SoapType2.xml.
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::IO; using namespace System::Xml; using namespace System::Xml::Serialization; [SoapType("EmployeeType")] public ref class Employee { public: String^ Name; }; // The SoapType is overridden when the // SerializeOverride method is called. [SoapType("SoapGroupType","http://www.cohowinery.com")] public ref class Group { public: String^ GroupName; array<Employee^>^Employees; }; public ref class Run { public: void SerializeOriginal( String^ filename ) { // Create an instance of the XmlSerializer class that // can be used for serializing as a SOAP message. XmlTypeMapping^ mapp = (gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid ); XmlSerializer^ mySerializer = gcnew XmlSerializer( mapp ); // Writing the file requires a TextWriter. TextWriter^ writer = gcnew StreamWriter( filename ); // Create an XML text writer. XmlTextWriter^ xmlWriter = gcnew XmlTextWriter( writer ); xmlWriter->Formatting = Formatting::Indented; xmlWriter->Indentation = 2; // Create an instance of the class that will be serialized. Group^ myGroup = gcnew Group; // Set the Object* properties. myGroup->GroupName = ".NET"; Employee^ e1 = gcnew Employee; e1->Name = "Pat"; myGroup->Employees = gcnew array<Employee^>(1); myGroup->Employees[ 0 ] = e1; // Write the root element. xmlWriter->WriteStartElement( "root" ); // Serialize the class. mySerializer->Serialize( xmlWriter, myGroup ); // Close the root tag. xmlWriter->WriteEndElement(); // Close the XmlWriter. xmlWriter->Close(); // Close the TextWriter. writer->Close(); } void SerializeOverride( String^ filename ) { // Create an instance of the XmlSerializer class that // uses a SoapAttributeOverrides Object*. XmlSerializer^ mySerializer = CreateOverrideSerializer(); // Writing the file requires a TextWriter. TextWriter^ writer = gcnew StreamWriter( filename ); // Create an XML text writer. XmlTextWriter^ xmlWriter = gcnew XmlTextWriter( writer ); xmlWriter->Formatting = Formatting::Indented; xmlWriter->Indentation = 2; // Create an instance of the class that will be serialized. Group^ myGroup = gcnew Group; // Set the Object* properties. myGroup->GroupName = ".NET"; Employee^ e1 = gcnew Employee; e1->Name = "Pat"; myGroup->Employees = gcnew array<Employee^>(1); myGroup->Employees[ 0 ] = e1; // Write the root element. xmlWriter->WriteStartElement( "root" ); // Serialize the class. mySerializer->Serialize( xmlWriter, myGroup ); // Close the root tag. xmlWriter->WriteEndElement(); // Close the XmlWriter. xmlWriter->Close(); // Close the TextWriter. writer->Close(); } void DeserializeObject( String^ filename ) { // Create an instance of the XmlSerializer class. XmlSerializer^ mySerializer = CreateOverrideSerializer(); // Reading the file requires a TextReader. TextReader^ reader = gcnew StreamReader( filename ); // Create an XML text reader. XmlTextReader^ xmlReader = gcnew XmlTextReader( reader ); xmlReader->ReadStartElement(); // Deserialize and cast the object. Group^ myGroup; myGroup = dynamic_cast<Group^>(mySerializer->Deserialize( xmlReader )); xmlReader->ReadEndElement(); Console::WriteLine( "The GroupName is {0}", myGroup->GroupName ); Console::WriteLine( "Look at the SoapType.xml and SoapType2.xml " "files for the generated XML." ); // Close the readers. xmlReader->Close(); reader->Close(); } private: XmlSerializer^ CreateOverrideSerializer() { // Create and return an XmlSerializer instance used to // and create SOAP messages. SoapAttributeOverrides^ mySoapAttributeOverrides = gcnew SoapAttributeOverrides; SoapAttributes^ soapAtts = gcnew SoapAttributes; // Override the SoapTypeAttribute. SoapTypeAttribute^ soapType = gcnew SoapTypeAttribute; soapType->TypeName = "Team"; soapType->IncludeInSchema = false; soapType->Namespace = "http://www.microsoft.com"; soapAtts->SoapType = soapType; mySoapAttributeOverrides->Add( Group::typeid, soapAtts ); // Create an XmlTypeMapping that is used to create an instance // of the XmlSerializer. Then return the XmlSerializer Object*. XmlTypeMapping^ myMapping = (gcnew SoapReflectionImporter( mySoapAttributeOverrides ))->ImportTypeMapping( Group::typeid ); XmlSerializer^ ser = gcnew XmlSerializer( myMapping ); return ser; } }; int main() { Run^ test = gcnew Run; test->SerializeOriginal( "SoapType.xml" ); test->SerializeOverride( "SoapType2.xml" ); test->DeserializeObject( "SoapType2.xml" ); }
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.




