wcf Getting started with wcf

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


This section provides an overview of what wcf is, and why a developer might want to use it.

It should also mention any large subjects within wcf, and link out to the related topics. Since the Documentation for wcf is new, you may need to create initial versions of those related topics.

Simple WCF service

Minimal requirements for WCF service is one ServiceContract with one OperationContract.

Service contract:

public interface IDemoService
    CompositeType SampleMethod();

Service contract implementation:

public class DemoService : IDemoService
    public CompositeType SampleMethod()
        return new CompositeType { Value = "foo", Quantity = 3 };

Configuration file:

<?xml version="1.0"?>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2"/>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>


public class CompositeType
    public string Value { get; set; }

    public int Quantity { get; set; }

WCF Restful Service Demo


 public class WCFRestfulService : IWCFRestfulService 
       public string GetServiceName(int Id)
            return "This is a WCF Restful Service";


[ServiceContract(Name = "WCRestfulService ")]
public interface IWCFRestfulService 
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetServiceName?Id={Id}")]
    string GetServiceName(int Id);

svc Markup (Right Click on svc file & click view MarkUp)

<%@ ServiceHost Language="C#" Debug="true" Service="NamespaceName.WCFRestfulService" CodeBehind="WCFRestfulService.svc.cs" %>

Web Config

      <service name="NamespaceName.WCFRestfulService" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="NamespaceName.IWCFRestfulService" behaviorConfiguration="web"/>
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        <behavior name="web">

Now Simply Run the Service or host in a port. And access the service using "http://hostname/WCFRestfulService/GetServiceName?Id=1"

Got any wcf Question?