Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Because a SOAP message is built using XML, the XmlSerializer class can be used to serialize classes and generate encoded SOAP messages. The resulting XML conforms to section 5 of the World Wide Web Consortium document "Simple Object Access Protocol (SOAP) 1.1". When you are creating an XML Web service that communicates through SOAP messages, you can customize the XML stream by applying a set of special SOAP attributes to classes and members of classes. For a list of attributes, see Attributes That Control Encoded SOAP Serialization.
To serialize an object as a SOAP-encoded XML stream
Create the class using the XML Schema Definition Tool (Xsd.exe).
Apply one or more of the special attributes found in
System.Xml.Serialization. See the list in "Attributes That Control Encoded SOAP Serialization."Create an
XmlTypeMappingby creating a newSoapReflectionImporter, and invoking theImportTypeMappingmethod with the type of the serialized class.The following code example calls the
ImportTypeMappingmethod of theSoapReflectionImporterclass to create anXmlTypeMapping.' Serializes a class named Group as a SOAP message. Dim myTypeMapping As XmlTypeMapping = New SoapReflectionImporter().ImportTypeMapping(GetType(Group))// Serializes a class named Group as a SOAP message. XmlTypeMapping myTypeMapping = new SoapReflectionImporter().ImportTypeMapping(typeof(Group));Create an instance of the
XmlSerializerclass by passing theXmlTypeMappingto the XmlSerializer(XmlTypeMapping) constructor.Dim mySerializer As XmlSerializer = New XmlSerializer(myTypeMapping)XmlSerializer mySerializer = new XmlSerializer(myTypeMapping);Call the
SerializeorDeserializemethod.
Example
' Serializes a class named Group as a SOAP message.
Dim myTypeMapping As XmlTypeMapping =
New SoapReflectionImporter().ImportTypeMapping(GetType(Group))
Dim mySerializer As XmlSerializer = New XmlSerializer(myTypeMapping)
// Serializes a class named Group as a SOAP message.
XmlTypeMapping myTypeMapping =
new SoapReflectionImporter().ImportTypeMapping(typeof(Group));
XmlSerializer mySerializer = new XmlSerializer(myTypeMapping);