Rich Web client development with Silverlight,LINQ , WCF and now Prism

Thursday, May 28, 2009

WCF Tips

Default Serialization
.NET 3.5 SP1 has introduced a new kink: if you don't decorate your class at all (omit / not add the [DataContract] attribute) then the object becomes "fully" serializable by WCF. All public properties will be automatically included.
so the serialzation of
[DataContract]
class foo
{
[DataMember]
public string test;
}

is the same as as :

class foo
{
public string test;
}

2. Visibility
Similar to service contracts, the visibility of the data members or the data contract itself is of no consequence to WCF. You can include internal types with private data members in the data contract:

[DataContract]
struct Contact
{
[DataMember]
string m_FirstName;

[DataMember]
string m_LastName;
}

3 deserializing event
Since no constructor calls are ever made during deserialization, the deserializing event-handling method is logically your deserialization constructor. It is intended for performing some custom pre-deserialization steps typically in a constructor.

for more details see http://codeidol.com/csharp/wcf/Data-Contracts/Data-Contract-Attributes/

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home