Solved

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

Posted on 2012-03-26
3
731 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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