Writing First WCF Service

This article will shows you how to create your first WCF service.

  • Open Visual Studio
  • Click File -> New -> Project
  • Select Visual C# -> WCF -> WCF Service Application and give service name and click on "OK".

    First wcf service

  • Delete the default operation contracts in Interface IService1.cs
  • Delete the defult method implementations (of interface) in Service Service1.svc.cs
  • Add new operation contract in Interface IService1.cs and give name as "GetDateTime"
    [ServiceContract] public interface IService1 { [OperationContract] string GetDateTime(); }
  • Implement the "GetDateTime" method in Service Service1.svc.cs
    public class Service1 : IService1 { public string GetDateTime() { return string.Format("Cureent Date & Time is ", DateTime.Now.ToString()); } }

In the next article we will see how to consume this WCF service in asp.net application. Consuming WCF service in asp.net application