Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating an API 4 173
WCF Service without a client 8 83
send receive image files via Wcf restful service client 6 42
WCF Rest JSON Serialization 12 96
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

16 Experts available now in Live!

Get 1:1 Help Now