Solved

Can I use Serializable Attribute instead of DataContract Attribute in WCF  ?

Posted on 2012-03-26
3
718 Views
Last Modified: 2012-06-22
I have a goal to migrate WEB Services to  WCF( wsHttpBinding;)
Is it possible  DO not PROVIDE A  DataContract attribute   for classes/ parameters migrated ,
just live  Serializable Attribute instead?
0
Comment
Question by:Yampolka
  • 2
3 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37770105
Yes it is, the only difference however is that using serializable you can only serialize fields and not properties.

Also serializable work on opt out model where in a field that don't want to get serialized has to mark itself as nonserialized, however DataContract works on OptIn approach where any property that wants to get serialized has to mark itself as DataMember.

Also serializable will serialize the assembly information in stream along with object state, however DC only writes state to stream(XML) which is what is required in SOA.

Here is a comparison:-
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/be796bd0-2502-4bd3-96d9-60bf7d68930d/
http://msdn.microsoft.com/en-us/library/ms730035.aspx
0
 

Author Comment

by:Yampolka
ID: 37770950
Thanks a lot .
As I understood correctly  serializable and datacontract attributes provide different serialization engines behind the scenes. If some classes  are serializable by default    and do not need 'serializable' attribute  to be serialized   like Dataset ?
Should I provide DataContract  attribute for DataSet?.
How WCF works with ADO.NET classes ?What kind of serialization it use?
And  could you  please tell  me what does it mean opt out and opt in model?
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37771034
for dataset since it is marked serializable, so it will be serialized automatically be netdatacontractserializer.

Opt Out approach means that all members of you object will serialized by default, the one which you don't want to serialize, you must mark them with [NonSerialized] attribute. This will opt them out of serialization.

However in DataContract, by default no members will be serialized until you mark them with DataMember or until they opt in for serialization.

Hope your doubts are clear and you close this question now....
Suggest you google more about DC and Serialization in .Net....
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This tutorial will show you how to add an attribute to an XML (http://en.wikipedia.org/wiki/XML) stream returned from a Windows Communication Foundation (http://en.wikipedia.org/wiki/Windows_Communication_Foundation) (WCF) Web Service.  Some knowled…
In previous Articles, we have discussed how we can upload a file using .asmx web service and isolated storage space. Here, in continuation to the topic, I am going to discuss how we can use WCF for the same purpose. Steps: 1.Create the silverli…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now