XML 和 SOAP 序列化XML and SOAP serialization

XML 序列化将对象的公共字段和属性以及方法的参数和返回值转换(序列化)为符合特定 XML 架构定义语言 (XSD) 文档的 XML 流。XML serialization converts (serializes) the public fields and properties of an object, and the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document. XML 序列化会生成强类型类,同时将公共属性和字段转换为序列格式(在此情况下为 XML),以便存储或传输。XML serialization results in strongly typed classes with public properties and fields that are converted to a serial format (in this case, XML) for storage or transport.

由于 XML 是开放式的标准,因此可以根据需要由任何应用程序处理 XML 流,而与平台无关。Because XML is an open standard, the XML stream can be processed by any application, as needed, regardless of platform. 例如,用 ASP.NET 创建的 XML Web services 使用 XmlSerializer 类来创建 XML 流,这些流在整个 Internet 中或在 Intranet 上的 XML Web services 应用程序之间传递数据。For example, XML Web services created using ASP.NET use the XmlSerializer class to create XML streams that pass data between XML Web service applications throughout the Internet or on intranets. 相反,反序列化采用这样一个 XML 流并重新构造对象。Conversely, deserialization takes such an XML stream and reconstructs the object.

XML 序列化还可用于将对象序列化为符合 SOAP 规范的 XML 流。XML serialization can also be used to serialize objects into XML streams that conform to the SOAP specification. SOAP 是一种基于 XML 的协议,它是专门为使用 XML 来传输过程调用而设计的。SOAP is a protocol based on XML, designed specifically to transport procedure calls using XML.

若要序列化或反序列化对象,请使用 XmlSerializer 类。To serialize or deserialize objects, use the XmlSerializer class. 要创建待序列化的类,请使用 XML 架构定义工具。To create the classes to be serialized, use the XML Schema Definition tool.

请参阅See also