Serialization  What is Serialization?  System.Serialization  Scenarios in Serialization  Basic Serialization  Custom Serialization.

Slides:



Advertisements
Similar presentations
Slide 10.1 Advanced Programming 2004, based on LY Stefanus’s Slides Object Serialization Object serialization: the process of converting an object into.
Advertisements

.Net Remoting Pooja Panjala 06/17/10. Agenda What is.net Remoting? Explanation of terms Architecture Implementation of Remoting Sample example.net Security.
C# and Windows Programming Application Domains and Remoting.
Object Oriented Programming Files and Streams Dr. Mike Spann
Some Useful.NET Techniques Blair Schneider McKay Clareos, Inc. Presented.
Serialization objects created in a program reside in RAM through references object o; heap stack content.
Portable binary serialization, the Google way
Unit 211 File IO Binary Files Reading and Writing Binary Files Writing Objects to files Reading Objects from files.
History, Architecture, and Implementation of the CLR Serialization and Formatter Classes Peter de Jong April 24, 2003.
Unit 201 File IO Binary Files Reading and Writing Binary Files Writing Objects to files Reading Objects from files.
Advanced Java Class Serialization. Serialization – what and why? What? –Translating the contents of an Object to a series of bytes that represent it,
Visual Basic: An Object Oriented Approach 4: Simple Programming in VB.
ASP.NET Programming with C# and SQL Server First Edition
Sequential-access file Create, read and write an object into a sequential-access file Serialize and deserialize the object to write and read from a data.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
Windows Programming Using C# Windows Services, Serialization, and Isolated Storage.
Ch 1. Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
.NET Framework Introduction: Metadata
1 Binary Files ผศ. ดร. หมัดอามีน หมันหลิน Faculty of IST, MUT
Avro Apache Course: Distributed class Student ID: AM Name: Azzaya Galbazar
Advanced .NET Programming I 13th Lecture
Creating and Running Your First C# Program Svetlin Nakov Telerik Corporation
HeuristicLab. Motivation  less memory pressure no DOM single pass linear process  less developer effort no interfaces to implement  modularity & flexibility.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
Lector: Aliyev H.U. Lecture №5 Telecommunication network software design with.NET. Using streams for network programming TASHKENT UNIVERSITY OF INFORMATION.
CSCI 6962: Server-side Design and Programming Web Services.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Component-Based Software Engineering Introduction to.NET Paul Krause.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
Object Persistence and Object serialization CSNB534 Asma Shakil.
Serialization What is Serialization Serialization is the process of converting an object, or a connected graph of objects, stored within computer memory,
By: PHANIDEEP NARRA. OVERVIEW Definition Motivation.NET and J2EE Architectures Interoperability Problems Interoperability Technologies Conclusion and.
Copyright 2012 & 2015 – Noah Mendelsohn A Brief Intro to the RPC Project Framework Noah Mendelsohn Tufts University
Lecture 19 Serialization Richard Gesick. Serialization Sometimes it is easier to read or write entire objects than to read and write individual fields.
CS360 Windows Programming
Intro to dot Net Dr. John Abraham UTPA CSCI 3327.
CIS 270—App Dev II Big Java Chapter 19 Files and Streams.
BIM313 – Advanced Programming File Operations 1. Contents Structure of a File Reading/Writing Texts from/to Files File and Directory Operations 2.
Object Serialization.  When the data was output to disk, certain information was lost, such as the type of each value.  If the value "3" is read from.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15.
Input and Output 23: Input and Output
28-June-2002cse142-C2-Classes © 2002 University of Washington1 Classes CSE 142, Summer 2002 Computer Programming 1
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 20.
1 Copyright © 2011 Tata Consultancy Services Limited TCS Internal.
.NET XML Web Services by Joe Mayo Mayo Software Consulting
.Net Reflection Taipan Tamsare. Overview Reflection core concepts Exploring metadata Detail information Attributes Building Types at runtime.
1 CSE 331 Memento Pattern and Serialization slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
.NET Framework Advanced Topics Name Title Department Company.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
Input and Output 23: Input and Output
Advanced .NET Programming II 6th Lecture
Presentation 23 .NET Remoting Introduced
Serialization.
CHAPTER 5 JAVA FILE INPUT/OUTPUT
Lectures 12 Files & Streams Dr. Eng. Ibrahim El-Nahry.
Introduction to C# AKEEL AHMED.
Chapter 23 – ASP.NET Outline 23.1 Introduction NET Overview
The command invocation protocol
Object Oriented Programming
CSE 331 Memento Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Fundaments of Game Design
Chapter 42 Web Services.
Quiz Points 3 Rules Raise your hand if you know the question
The command invocation protocol
Jim Fawcett CSE775 – Distributed Objects Spring 2006
Presentation transcript:

Serialization  What is Serialization?  System.Serialization  Scenarios in Serialization  Basic Serialization  Custom Serialization

Serialization/Deserialization Object in memory …binary or character stream…

Serialization What is Serialization  Serialization is the process of converting an object, or a connected graph of objects, stored within computer memory, into a linear sequence of bytes  Use the sequence of bytes in several ways: Send it to another process Send it to the clipboard, to be browsed or used by another application Send it to another machine Send it to a file on disk

Serialization Object Graph  What is an object graph? An object graph is a set of objects with some set of references to each other The most obvious problem is how to represent the links between the objects in the Serialized stream Cat Mouse Duck Dog Horse

Serialization How Serialization Works  Because run-time metadata 'knows' about each object's layout in memory, and its field and property definitions, you can serialize objects automatically, without having to write code to serialize each field  The serialized stream might be encoded using XML, or a compact binary representation  The format is decided by the the Formatter object that you call: Binary SOAP Custom

Serializaiton FileStream Example class SerializeExample{ public static void Main(String[] args) { ArrayList l = new ArrayList(); for (int x=0; x< 100; x++) { l.Add (x); } // create the object graph FileStream s = File.Create("foo.bin"); // create the filestream BinaryFormatter b = new BinaryFormatter(); // create the BinaryFormatter b.Serialize(s, l); // serialize the graph to the stream } // end main } // end class

Serializaiton Deserialize Example using System; using System.IO; using System.Collections; using System.Serialization; using System.Serialization.Formatters.Binary; class DeSerialize { public static void Main(String[] args) { FileStream s = File.Open("foo.bin"); // open the filestream BinaryFormatter b = new BinaryFormatter(); // create the formatter ArrayList p = (ArrayList) b.Deserialize(s); // deserialize p.ToString(); // print out the new object graph } // end Main } // end Class DeSerialize

Serialization Basic Serialization  A Type is NOT Serializable unless Type is specifically marked as Serializable  The Serializable Attribute  The Non-Serializable Attribute [Serializable] public class MyClass {} [Serializable] public class MyClass { [NotSerialized] int _cashSize; }

.NET Serialization Facilities Take an extremely simple C# class: public class InitialConfiguration { public enum Difficulty {hard, medium, easy}; public InitialConfiguration() { } public Difficulty starting = Difficulty.medium; }

.NET Serialization Facilities Use.NET library functions to serialize it: InitialConfiguration conf = new InitialConfiguration(); XmlSerializer ser = new XmlSerializer(typeof(InitialConfiguration)); XmlTextWriter writer = new XmlTextWriter( stream, System.Text.Encoding.UTF8); ser.Serialize(writer, conf);

.NET Serialization Facilities Get XML: <InitialConfiguration xmlns:xsd=" xmlns:xsi=" medium

Serialization Customize Serialization  Implementing ISerializable interface  IDeserializationEventListener  Custom Formatters

Serialization ISerializable Interface  Customize the serialization process  If a class implements ISerializable, that interface will always be called in preference to default serialization.  The ISerializable interface is only contains one method: void GetObjectData (SerializationInfo info, StreamingContext context); And an implied constructor that may be private. private (SerializationInfo info, StreamingContext)

Serialization IDeserializationEventListener  If an object implements IDeserializationEventListener, the serialization infrastructure will call that class‘ OnDeserialization method as soon as the entire graph has been deserialized and all fix- ups completed  Provide a reasonable opportunity for objects that need to do fix-ups based on the state of their children

Serialization Custom Formatter  Implementing IFormatter Interface: public interface IFormatter: { //Properties SerializationBinder Binder { get; set; } StreamingContext Context { get; set; } ISurrogateSelector SurrogateSelector { get; set; } //Methods object Deserialize(Stream serializationStream); void Serialize(Stream serializationStream, object graph); }

Conclusion  Types' metadata can be explored with Reflection  Reflection provides dynamic type system  The Federated Services Model is one of the core concepts for designing.NET applications in Internet  Key.NET Remoting scenarios are: Web Services Anywhere CLR Object Remoting  Serialization is the process of converting an object, or a connected graph of objects, stored within computer memory, into a linear sequence of bytes

Resources  .NET Framework SDK