Serialization and Deserialization and Activation Models in Remoting in C#.Net
Check out Best Alternative to InfoPath -> Try Now
This C#.Net tutorial, we will discuss Serialization and Deserialization in C#.Net in Remoting and also, we will discuss Activation Models in Remoting in C#.Net.
Serialization and Deserialization in Remoting in C#.Net
Serialization and Deserialization basically used in Distributed Applications like Remoting, Webservice, WCF, etc. These are explained below.
Serialization and Deserialization in Remoting
- To exchange the information between both the parties i.e, client and server they use the process Serialization and Deserialization.
- An application represents the data in high level (object format) which can’t flow freely, it needs to convert into low level(binary or text) and then it transferred to other systems where on the target machine low-level data has to be converted back into the high level.
- Serialization is a process of converting high-level data to low-level data and De-serialization is the process of converting low-level data to high-level data.
- If the client and server in one OS, it is the Binary format and if they are in different OS, it is Text format.
- Remoting provides Formatter Classes to perform Serialization and Deserialization.
These are as follows:
Soap Formatters: HttpServerChannel,HttpClientChannel
Soap Formatted are used for text serialization and deserialization and Binary Formatters are used for binary serialization and deserialization.
Binary Formatters: TCP server channel, TCPClientChannel
Binary is more efficient (time and memory used) and not human readable. Soap is human readable. We can serialize our own classes if we mark them as [Serializable] attribute that means it serializes all members of a class, except those marked as [NonSerialized].
Activation Models in Remoting in C#.Net
Now, we will see what are activation models in remoting in C#.Net.
.NET Remoting is a mechanism for communicating between objects which are not in the same process that means in Remoting we can consume assemblies residing on remote machines. For the execution of Remoting, application client needs an object of the remote class to invoke the method under it. Activation Models decide where the remote class objects reside in the execution of the applications.
Remoting supports 2 different Activation Models:
- Server Activated Objects(SAO)
- Client Activated Objects(CAO)
Server Activated Objects:
In SAO model object of remote class resides on server Machine and a reference of this object is maintained on the client machine using which clients can invoke the methods of the remote class. In the SAO model again 2 types of object mode required for server activation. This can be Singleton or SingleCall .
Singleton -> In this mode whenever a first request comes from a client, an object of the remote class gets created and its reference is given to the client. From then every new request coming from a new client, the server provides the reference of the same object which is already created, so changes made by one client gets reflected to the other. This is used in the development of an application like, “cricket score”,”public chats” etc. A Singleton, on the other hand, only gets one instance created for ALL incoming requests. Singleton builds a single object to handle multiple calls allowing data sharing but limits simultaneous connections
Singlecall -> In this mode whenever a request comes from a client one object of the remote class gets created and its reference is given to the client. Once the request is served immediately object gets destroyed without allowing to make another request on that object. For a new request, a new object gets created again and destroyed. This is used in the development of single request application like, “ATM Machines”, “Railway PNR status inquiry” and “Examination Results”. This is a very highly secured model used in application development. SingleCall builds the object per each call and can accept multiple simultaneous requests, but data can’t be shared between calls. Single Call objects are usually not required to store state information, and they cannot hold state information between method calls.
Client Activated Objects(CAO):
Client-activated objects (CAO) are server-side objects that are activated upon request from the client. In this mode whenever the first request comes from a client an object of the remote class is created and provided, using which the client can make any no.of requests. Here a separate object will be given for each client so changes made by one client will never reflect to the other. This is used in the development of applications that requires multiple requests for a single client like “Traditional ATM machines”, where we can perform multiple transactions once we insert the card. Client-activated objects can store state information between method calls for its specific client, and not across different client objects.
You may also like following C#.Net tutorials:
- How to create a GUID in C#.Net
- C#.Net Collection tutorial
- Working with Files in C#.Net
- C#.Net Dictionary Table class
- Delegates in C#.Net
- Method Overloading and Method overriding C#.Net
- OpenFileDialog in C#.Net windows application
- How to place C#.Net windows application to System Tray?
- Retrieve browser details using C#.Net
- Exception Class in C#.Net
- Add user to a group in active directory using C#.Net
- Create generics lists in C#.Net
- Disable or Hide minimize maximize and close buttons in C#.net windows form
This C#.Net tutorial, we learned Serialization and Deserialization in C#.Net in Remoting and various activation models in remoting in C#.Net.
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.