Creating and consuming WCF Services

Create a WCF Service Application
Run it, right click on the service and copy the address

Create a custom class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SandCastleServices
public class TestClass
public int Id;
public string Name;
public List<string> WordList;

in Service.svc.cs add function
public TestClass GetTestClass()
TestClass newClass = new TestClass();
newClass.Id = 3;
newClass.Name = “Test3″;
newClass.WordList = new List<string>();

return newClass;

in IService.cs add an Operation contract
TestClass GetTestClass();

Create a Web Project
Right click on the project and coick on “Add Service Reference”
Paste the address

In the code:
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
string test = client.GetData(89);

//This is how you get a custom class
ServiceReference1.TestClass testClass = client.GetTestClass();

Leave a Reply