code 39 c# class XML S ERIA LIZA TION in C#

Drawer Code 39 Full ASCII in C# XML S ERIA LIZA TION

CHAPTER 8 XML S ERIA LIZA TION
Print ANSI/AIM Code 39 In C#
Using Barcode creator for VS .NET Control to generate, create Code39 image in Visual Studio .NET applications.
www.OnBarcode.com
Code-39 Recognizer In C#
Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Figure 8-8. Object serialized in SOAP format
Barcode Creator In Visual C#
Using Barcode generator for .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
DataMatrix Generator In C#.NET
Using Barcode printer for .NET framework Control to generate, create Data Matrix 2d barcode image in .NET framework applications.
www.OnBarcode.com
Customizing SOAP Serialization
Making Code 3 Of 9 In Visual C#
Using Barcode encoder for .NET framework Control to generate, create Code39 image in .NET framework applications.
www.OnBarcode.com
Draw UCC-128 In Visual C#.NET
Using Barcode maker for VS .NET Control to generate, create UCC - 12 image in .NET framework applications.
www.OnBarcode.com
Just as we customized the serialization process during XML serialization, we can customize the SAP serialization also. There are two ways to achieve this: Implement the ISerializable interface. Use certain serialization and deserialization attributes. The first method has been available since .NET Framework 1.x. The latter method was introduced in .NET 2.0 and supersedes the first method. In our example, we are going to use the latter method to customize the serialization process. We will use the same application that we developed in the previous section while illustrating the use of the SoapFormatter class. Suppose that you wish to protect the serialized XML data from casual users. You want to implement Base64 encoding to the data that is being serialized so that casual readers cannot easily read the contents. That data needs to be encoded in a Base64 encoding scheme and decoded when deserialized. In such cases, the custom serialization attributes come in handy. Add two helper functions called Encode() and Decode() to the preceding application as shown in Listing 8-20.
Generate Linear Barcode In C#
Using Barcode printer for .NET Control to generate, create Linear image in VS .NET applications.
www.OnBarcode.com
Painting Code 93 Extended In C#.NET
Using Barcode maker for Visual Studio .NET Control to generate, create Code 93 Extended image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 8 XML S ERIA LIZATION
Code-39 Decoder In Visual C#
Using Barcode recognizer for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Make Code39 In Java
Using Barcode encoder for Android Control to generate, create ANSI/AIM Code 39 image in Android applications.
www.OnBarcode.com
Listing 8-20. Encoding and Decoding Data by Using Base64 Encoding private string Encode(string str) { byte[] data = ASCIIEncoding.ASCII.GetBytes(str); return Convert.ToBase64String(data); } private string Decode(string str) { byte[] data=Convert.FromBase64String(str); return ASCIIEncoding.ASCII.GetString(data); } The Encode() function accepts a string that is to be encoded in Base64 format. It then converts the string into a byte array by using the GetBytes() method of the ASCIIEncoding class. The byte array is then fed to the ToBase64String() method of the Convert class, which returns a Base64-encoded string representing the supplied array of bytes. The Decode() function accepts a Base64-encoded string that is to be decoded back to a plain string representation. It then calls the FromBase64String() method of the Convert class and passes the supplied Base64 string to it. The FromBase64String() method returns a byte array representing the decoded version of the supplied string. The byte array is converted to a string by using the GetString() method of the ASCIIEncoding class. Now we need to add four methods to our class, as shown in Listing 8-21. Listing 8-21. Customizing SOAP Serialization and Deserialization [OnSerializing] public void OnSerializing(StreamingContext context) { strFName = Encode(strFName); strLName = Encode(strLName); strHPhone = Encode(strHPhone); strNotes = Encode(strNotes); } [OnSerialized] public void OnSerialized(StreamingContext context) { strFName = Decode(strFName); strLName = Decode(strLName); strHPhone = Decode(strHPhone); strNotes = Decode(strNotes); }
EAN-13 Creation In Visual Studio .NET
Using Barcode printer for ASP.NET Control to generate, create EAN-13 Supplement 5 image in ASP.NET applications.
www.OnBarcode.com
Code 128C Creation In Objective-C
Using Barcode encoder for iPhone Control to generate, create Code 128B image in iPhone applications.
www.OnBarcode.com
CHAPTER 8 XML S ERIA LIZA TION
GS1 128 Printer In None
Using Barcode creator for Excel Control to generate, create UCC.EAN - 128 image in Excel applications.
www.OnBarcode.com
EAN / UCC - 14 Generation In None
Using Barcode creator for Online Control to generate, create UCC.EAN - 128 image in Online applications.
www.OnBarcode.com
[OnDeserializing] public void OnDeserializing(StreamingContext context) { //no code here } [OnDeserialized] public void OnDeserialized(StreamingContext context) { strFName = Decode(strFName); strLName = Decode(strLName); strHPhone = Decode(strHPhone); strNotes = Decode(strNotes); } The four methods are marked with the [OnSerializing], [OnSerialized], [OnDeserializing], and [OnDeserialized] attributes. These attributes allow you to customize the serialization and deserialization process by using pre- and post-methods: The method marked with [OnSerializing] is automatically called by the serialization framework before the data is serialized. The method marked with [OnSerialized] is called when the serialization is complete. Similarly, the methods marked with [OnDeserializing] and [OnDeserialized] are called before and after the deserialization operation. All these methods must accept a parameter of type StreamingContext. The StreamingContext parameter provides additional information about the serialization or deserialization process. In our example, the OnSerializing() method calls the Encode() helper method that we created earlier to encode the variable values into Base64 format. Thus the data being serialized is not a plain string but a Base64 string. After the serialization is complete, we may still need the same data in plain-string format. That is why the Decode() method is called in the OnSerialized() method. The OnDeserializing() method doesn t include any code in our example. However, if you wish to execute some code before deserialization takes place, you can add your custom logic in this method. After the previously serialized data is deserialized, it should give us the values in plain-string format and not in Base64 format. Hence the OnDeserialized() method calls Decode() and converts the Base64 values into plain text. Figure 8-9 shows a sample run of the application.
PDF-417 2d Barcode Recognizer In Visual C#.NET
Using Barcode reader for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Paint Code 128C In VB.NET
Using Barcode creation for VS .NET Control to generate, create Code 128 image in Visual Studio .NET applications.
www.OnBarcode.com
EAN13 Generation In None
Using Barcode drawer for Font Control to generate, create EAN-13 image in Font applications.
www.OnBarcode.com
Encode PDF417 In .NET
Using Barcode encoder for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications.
www.OnBarcode.com
GTIN - 12 Scanner In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Barcode Printer In Java
Using Barcode drawer for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Copyright © OnBarcode.com . All rights reserved.