Solved

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

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

810 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