Interface

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace MyServiceInterface
{
[ServiceContract]
public interface IService1
{
[OperationContract]
int Add(int Number1, int Number2);
[OperationContract]
int Sub(int Number1, int Number2);
[OperationContract]
int Mul(int Number1, int Number2);
[OperationContract]
int Div(int Number1, int Number2);
}
[ServiceContract]
public interface IService2
{
[OperationContract]
[WebGet(UriTemplate = "/Add/{Number1}/{Number2}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
int AddRest(string Number1, string Number2);
[OperationContract]
[WebGet(UriTemplate = "/Sub/{Number1}/{Number2}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
int SubRest(string Number1, string Number2);
[OperationContract]
[WebGet(UriTemplate = "/Mul/{Number1}/{Number2}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
int MulRest(string Number1, string Number2);
[OperationContract]
[WebGet(UriTemplate = "/Div/{Number1}/{Number2}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
int DivRest(string Number1, string Number2);
}
}

Class

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

using MyServiceInterface;

namespace WebApplicationWCF
{
public class Service1 : IService1, IService2
{
public int Add(int Number1, int Number2)
{
return Number1 + Number2;
}
public int Sub(int Number1, int Number2)
{
return Number1 - Number2;
}
public int Mul(int Number1, int Number2)
{
return Number1 * Number2;
}
public int Div(int Number1, int Number2)
{
return Number1 / Number2;
}
public int AddRest(string Number1, string Number2)
{
int num1 = Convert.ToInt32(Number1);
int num2 = Convert.ToInt32(Number2);
return num1 + num2;
}
public int SubRest(string Number1, string Number2)
{
int num1 = Convert.ToInt32(Number1);
int num2 = Convert.ToInt32(Number2);
return num1 - num2;
}
public int MulRest(string Number1, string Number2)
{
int num1 = Convert.ToInt32(Number1);
int num2 = Convert.ToInt32(Number2);
return num1 * num2;
}
public int DivRest(string Number1, string Number2)
{
int num1 = Convert.ToInt32(Number1);
int num2 = Convert.ToInt32(Number2);
return num1 / num2;
}
}
}

Server

  1. <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

    <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
    </appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1"/>
    </system.web>

    <system.serviceModel>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
    <serviceActivations>
    <add service="WebApplicationWCF.Service1" relativeAddress="~/Service1.svc"/>
    </serviceActivations>
    </serviceHostingEnvironment>
    <behaviors>
    <serviceBehaviors>
    <behavior name ="servicebehavior">
    <serviceMetadata httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
    <behavior name="restbehavior">
    <webHttp/>
    </behavior>
    </endpointBehaviors>
    </behaviors>
    <services>
    <service name ="WebApplicationWCF.Service1" behaviorConfiguration ="servicebehavior" >
    <endpoint name ="SOAPEndPoint" contract ="MyServiceInterface.IService1" binding ="basicHttpBinding" address ="soap" />

     <endpoint name ="RESTEndPoint"
               contract ="MyServiceInterface.IService2"
               binding ="webHttpBinding"
               address ="rest"
               behaviorConfiguration ="restbehavior"/>
    
     <endpoint contract="IMetadataExchange"
               binding="mexHttpBinding"
               address="mex" />

    </service>
    </services>
    </system.serviceModel>

    <system.webServer>

    <modules runAllManagedModulesForAllRequests="true"/>
    <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. -->
    <directoryBrowse enabled="true"/>
    </system.webServer>
    </configuration>

  1. class Program
    {
    static void Main(string[] args)
    {
     Uri baseAddress = new Uri("http://localhost:8000/Service1.svc");
     WebServiceHost svcHost = new WebServiceHost(typeof(Service1), baseAddress);
     svcHost.AddServiceEndpoint(typeof(IService2), new WebHttpBinding(), "rest");
     try
     {
         svcHost.Open();
         Console.WriteLine("Service is running");
         Console.WriteLine("Press enter to quit...");
         Console.ReadLine();
         svcHost.Close();
     }
     catch (CommunicationException cex)
     {
         Console.WriteLine("An exception occurred: {0}", cex.Message);
         Console.ReadLine();
         svcHost.Abort();
     }
    }
    }