WCF Service and how call that service in a project

Kailash Singh
66 Points
28 Posts

Hello Sir, How to make a WCF service . and how call that service on project ? 

Views: 9114
Total Answered: 1
Total Marked As Answer: 0
Posted On: 10-Dec-2015 10:06

Share:   fb twitter linkedin
NiceOne Team
414 Points
67 Posts

Hi Kailash,

Follow the step to create a simple wcf service and use in other web project application

Creating wcf application:

i) create new wcf application project as:

ii) Now you can see service1.svc file is created automatically as the service.svc.cs code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. 
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
public class Service1 : IService1
public string GetData(int value)
return string.Format("You entered: {0}", value);
public CompositeType GetDataUsingDataContract(CompositeType composite)
if (composite == null)
throw new ArgumentNullException("composite");
if (composite.BoolValue)
composite.StringValue +="Suffix";
return composite;


iii) Now we will debug this application to test the GetData service method as in wcf test client:

In above test client you see out put "You entered: 10" for input 10. This means that service method is ok.

Creating Client Application:

i) Suppose you created a web form applcation project. Now you have to add reference of the existing service as shown in below image:

You can copy service address from the test client step(iii) other wise you can host this application to iis then the path.

ii) after clicking the ok button you can see the service reference added to the server explorer as:

iii) Now create a test page named as test page:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="testpage.aspx.cs" Inherits="WebApplication1.testpage" %>
<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head runat="server"> 
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication1.ServiceReference1;
namespace WebApplication1
public partial class testpage : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
Service1Client Client = new Service1Client(); 
string result = Client.GetData(10);
Label1.Text = result;

 web.config: client end point of the service is added automatically when service reference added

<?xml version="1.0"?>
<!--For more information on how to configure your ASP.NET application, please visit
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<binding name="BasicHttpBinding_IService1" />
<endpoint address="https://localhost:1185/Service1.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />

iv) Now you can debug the client application and you get the output as:

I think the above step will help you understand better.

Posted On: 10-Dec-2015 23:08
 Log In to Chat