Why we have to [Serializable] Attribute in the bussiness object class ?

Posted by Gg under ASP.NET on 7/30/2011 | Points: 10 | Views : 6126 | Status : [Member] | Replies : 1

Why we have to [Serializable] Attribute in the bussiness object class ?
what will happen If I wont use ?

public class EqueryRaised
#region Private Fields
private string _queryID;
private string _reOpenID;



Posted by: SheoNarayan on: 7/30/2011 [Administrator] HonoraryPlatinum | Points: 25

In order to understand this, first understand what is Serialization, It is a concept of converting an object to a format that can be stored on the disk or can be transferred over network. Deserialization is just opposite means converting the serialized data into the clone of original object. Read more about it at http://en.wikipedia.org/wiki/Serialization.

Now why Serializable attribute is needed? The simple answer is that in case you have or will have need to transfer the object from one location to another location (can be machine) via network (eg. you are exposing or consuming wcf or web services). You will have to use this attribute for all your objects that you are planning to consume or send to your consumer so that that class can become serializable and can be transferred via network.

If you will not use this attribute your object will be serialized (as a result you will not be able to expose or consume business objects in any of the services either wcf or web or similar). Read more about serializable attribute at http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx.

Hope this answer your question. Thanks for asking !

Sheo Narayan

Gg, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response