svc
public class WCFRestfulService : IWCFRestfulService
{
public string GetServiceName(int Id)
{
return "This is a WCF Restful Service";
}
}
Interface
[ServiceContract(Name = "WCRestfulService ")]
public interface IWCFRestfulService
{
[OperationContract]
[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
<services>
<service name="NamespaceName.WCFRestfulService" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="NamespaceName.IWCFRestfulService" behaviorConfiguration="web"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<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>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
Now Simply Run the Service or host in a port. And access the service using "http://hostname/WCFRestfulService/GetServiceName?Id=1"