Step 2
Remove
all the default code created by WCF. Remove code from IService 1
interface and Service1 class. Remove the code from Web.Config also.
Open Web.Config and remove System.Servicemodel codes.
Step 3
Right click on Service1.svc select View markup and add below code
<%@ ServiceHost Language="C#" Debug="true" Service="FetchingImageinBrowser.Service1" CodeBehind="Service1.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
Step 4
Create
contract. Operation contract will return Stream. Stream is in the
namespace System.IO. By putting WebGet attribute make operation contract
IService1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.ServiceModel.Web;
namespace WcfService6
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate="/GetData")]
string
GetData();
}
}
Step 5
Implement the service
Service1.svc.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService6
{
public class Service1 : IService1
{
public string GetData()
{
return "hello From REST ";
}
}
}
Press F5 to run the service
Consume the Service in ASP.Net Web Site
Step 1
Create an ASP.Net Web Site. Navigate to File -> New -> Web Site
Step 2
Drag and drop one button and text box on the page.
Step 3
Add the namespace of
System.RunTIme.Serilization
System.Net
System.IO
Step 4
On the click event of the button,
Refer Link:http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/consuming-wcf-rest-service-in-asp-net-web-site/
Refer Link:http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/uritemplate-class-in-wcf-rest-service-part-i/
This Link for Service Library:http://www.codeproject.com/Articles/167159/How-to-create-a-JSON-WCF-RESTful-Service-in-sec
Very important Reference: http://www.codeproject.com/Articles/259832/Consuming-Cross-Domain-WCF-REST-Services-with-jQue