
You can use both the attributes listed in "Attributes That Control XML Serialization" and "Attributes That Control Encoded SOAP Serialization" because an XML Web service can use either the literal or encoded SOAP style. To control the SOAP messages, you can apply attributes to the classes, return values, parameters, and fields found in an XML Web service file (.asmx).

The XmlSerializer class generates the SOAP messages created by, and passed to, XML Web services. For a table of the attributes that control the generated XML, see Attributes That Control Encoded SOAP Serialization. The generated XML adheres to section 5 of the World Wide Web Consortium document titled "Simple Object Access Protocol (SOAP) 1.1." For more information about this process, see How to: Serialize an Object as a SOAP-Encoded XML Stream. The XmlSerializer class can further serialize an object and generate an encoded SOAP XML stream. For a table of those attributes that are used to control the generated XML, see Attributes That Control XML Serialization.

For more information about these attributes and how they control XML serialization, see Controlling XML Serialization Using Attributes. In contrast, use the XmlSerializer when the XML stream is expected to conform to a known XML Schema.Īttributes control the XML stream generated by the XmlSerializer class, allowing you to set the XML namespace, element name, attribute name, and so on, of the XML stream. These classes allow you to parse any XML stream. For more information, see XML Documents and Data. NET, such as the XmlReader and XmlWriter classes, to parse and write an XML stream. This is an alternative to using other classes in. Provided with such a class, you can program against an easily manipulated object model while being assured that the generated XML conforms to the XML schema. When an instance of such a class is serialized, the generated XML adheres to the XML Schema. If you have an XML Schema, you can run the XML Schema Definition tool to produce a set of classes that are strongly typed to the schema and annotated with attributes. You have the option of creating your own classes, annotated with attributes, or using the XML Schema Definition tool to generate the classes based on an existing XML Schema. The data in your objects is described using programming language constructs like classes, fields, properties, primitive types, arrays, and even embedded XML in the form of XmlElement or XmlAttribute objects.


Furthermore, the data types generated are compliant with the document titled "XML Schema Part 2: Datatypes." The XML stream generated by the XmlSerializer is compliant with the World Wide Web Consortium (W3C) XML Schema definition language (XSD) 1.0 recommendation.
#Serialized generator#
The XML Serializer Generator Tool (Sgen.exe) is designed to generate these serialization assemblies in advance to be deployed with your application and improve startup performance. The XmlSerializer creates C# files and compiles them into. The central class in XML serialization is the XmlSerializer class, and the most important methods in this class are the Serialize and Deserialize methods. To serialize all an object's fields and properties, both public and private, use the DataContractSerializer instead of XML serialization. XML serialization does not convert methods, indexers, private fields, or read-only properties (except read-only collections).
