[DataContract] and [DataMember] Namespace with an example

DataContract and DataMember will come under System.Runtime.Serialization; namespace. Before using this namespace we have to add reference (System.Runtime.Serialization.dll) through Add Reference wizard.

In the below example CustData will work as a [DataContract] and [custName] will be [DataMember].

Please go through below example for reference.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Xml.Serialization;
using System.Runtime.Serialization;

namespace SelfHosting
{
    [ServiceContract]
    interface IService
    {
        [OperationContract]
        string insertData();
    }

    [DataContract]
    class CustData
    {
        [DataMember]
        int custid { get; set; }
        
        
       [DataMember]
string custName { get; set; } } class Service:IService { #region IService Members public string insertData() { return "success"; } #endregion } }


Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar