Title: Microsoft 'NET Framework and XML Serialization Advanced Saqib Rasool Developer Support Engineer PSS
1Microsoft .NET Framework and XML Serialization
(Advanced) Saqib RasoolDeveloper Support
EngineerPSS XML WebData Team Microsoft
Corporation
2Agenda
- Serialization recap
- Serialization example
- Customizing serialization
- Creating SOAP messages
- Usage of SOAP with serialization
- Note These slides provide only a summary. Read
the transcript or listen to the on-demand
recording of this WebCast for in-depth
information about this subject. Microsoft
Knowledge Base article Q323503, WebCast XML
Serialization and Sample Code contains a full
code sample.
3Serialization Recap
- Object serialization
- Saving/archiving an object to portable media
- Into a file, into memory, or straight to wire
- Deserialization
- Restructuring saved/archived object into a memory
lived object - System.Xml.Serialization namespace
- XmlSerializer class
- XmlSerializer.Serialize(..)
- XmlSerializer.Deserialize(..)
4Serialization Example
5Serialization ExampleSerialized Object
6Serialization ExampleDeserializing
7Serialization CustomizationsEarly Customizations
- Use attributes to control the serialization
- Example XmlElementAttribute
8Serialization Customizations (2)Early
Customizations
- Use attributes to control the serialization
- Example XmlRootAttribute
9Serialization CustomizationsAllowed
Customizations Using Attributes
- Use attributes to control the serialization
10Serialization CustomizationsLate Customization
- Can use attributes to change XML stream
- Late customization is needed when modifying the
original source code is not an option - See code on next slide
11Changing Output XML Stream with Overriding
12Before overriding
Changing Output XML Stream with Overriding (2)
After overriding
- You can also override the class used for
serialization
13Creating SOAP Messages
- The XmlSerializer can be used to generate
SOAP-encoded messages - Process
- SoapReflectionImporter. ImportTypeMapping(..)
creates XmlTypeMapping - Create XmlSerializer by passing above
XmlTypeMapping - Call XmlSerializer.Serialize() and
XmlSerializer.Deserialize() as needed
14Creating SOAP MessagesCode Sample
15SOAP-Encoded XML Stream
16Customizing SOAP Messages
- Customized and overridden in the same way as
regular serialization - These attributes are used for customization
17Customizing SOAP MessagesCode Sample
18Usage of SOAP with SerializationWeb Services
- Web Services use SOAP as the underlying mechanism
- XmlSerializer is used to create those SOAP-
encoded methods - Previously described techniques can be used to
change the output message format of the Web
Service
19SOAP Customization in Web ServicesCode Sample
20SOAP Customization in Web ServicesSOAP Envelope
for Calling Web Service
21SOAP and Binary Serialization with Formatters
- SoapFormatter and BinaryFormatter are different
than the techniques discussed earlier do not
confuse these with XmlSerializer - These formatters are found under the
System.Runtime.Serialization.Formatters namespace - These are used when full object fidelity is
required - BinaryFormatter is used for providing a compact
stream - SoapFormatter is used for portability
22Binary Formatter Code Sample
23SOAP Formatter Code Sample
24- Thank you for joining us for todays Microsoft
Support - WebCast.
- For information about all upcoming Support
WebCasts - and access to the archived content (streaming
media - files, PowerPoint slides, and transcripts),
visit - http//support.microsoft.com/webcasts/
- We sincerely appreciate your feedback. Please
send any - comments or suggestions regarding the Support
- WebCasts to supweb_at_microsoft.com.