IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
Windows Communication Foundation uses DataContractSerializer for the serialization and deserialization of the messages. While the topic of the serialization in WCF is beyond the scope of this article, we will give some quick start instructions as well as point some common problems that accompany serialization.
With the DataContractSerializer you are able to serialize objects in XML or JSON format, which is then transmitted to the client of the web service. There are two basic approaches to achieve this:
When preparing types for serialization (placing DataContract and DataMember attributes), you should have following in mind:
[DataContract]
public
class
Product
{
[DataMember]
Guid Id {
get
;
set
; }
Guid WarehouseId {
string
Name {
double
Price {
}
Often we will want to have our service to work with base class, while the actual instances served by the service will be derivations of such web service.
Consider following service and two data types.
ProductsService : IProducts
Product GetProduct()
return
new
Book();
[KnownType(
typeof
(Book))]
Book : Product
Notice, how in the service we have a method GetProduct which returns an object of type Product, yet we are returning an instance of Book type (which is perfectly valid, since Book type is deriving from Product type). However, in order for this scenario to work, we need to decorate the Product class with the KnownType attribute and set the type of Book as a known type for that DataContract.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important