[ServiceContract] and [OperationContract] Namespace with an example

[ServiceContract] and [OperationContract] Namespace is System.ServiceModel. Before using this one we have to add System.ServiceModel.dll through Add Reference.

Please check below example how to use serviceContract and operationContract in Console application.

This is also one of the good WCF Interview Question.

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; }

        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