WCF service – how to start?

WCF service allows you to use a huge functionality even though you have a slow local machine. Sounds good? Yes, it does. Let’s create a simple WCF service to add people. All coding is done with VS 2010 Ultimate.

What you need to do first is to create a new WCF Service Library.


When it is already done, please delete all default classes, which creator has added to your project automatically. Now follow these steps:

1) Prepare a simple class which will be responsible for a new object. Name it Person.cs – now add these lines of code:

namespace PeopleWcfService
using System.Runtime.Serialization;

public class Person
public string ItsName { get; set; }

public string ItsSurname { get; set; }

DataContract contains DataMembers – it allows to exchange data between client and server, so you need to remember to put it in each class responsible for new objects.

2) Create interface with methods responsible for adding people to a group and getting the list of them. Add a new interface to your project and name it IPersonWcfService.cs. Now add this code inside:

using System.Collections.Generic;

namespace PeopleWcfService
    using System.ServiceModel;

    public interface IPersonWcfService
        void AddPerson(Person person);

        List<Person> GetPeople();

I always create interfaces (recommended) to define ServiceContracts,  but you can also use classes. Please remember to add [OperationContract] to each method.

3) The last thing to do is to add code to our interface’s methods. Please create a new class called PersonWcfService.cs and add this code behind:

using System.Collections.Generic;

namespace PeopleWcfService
    public class PersonWcfService : IPersonWcfService
        private readonly List<Person> peopleList = new List<Person>();

        #region IPersonWcfService Members

        public void AddPerson(Person person)

        public List<Person> GetPeople()
            return peopleList;


4) When previous steps are already finished you should build your application. When it is built please edit App.config file for your project. Right-click at App.config and select as below:



And now you need to configure your WCF service:



When you select (…) (2nd red point) navigate to bin/Debug and click twice on PersonWcfService.dll. Then you will be able to select your interface (PeopleWcfService.IPersonWcfService) -> click Open button.

Another thing that you have to do is to configure this:



Same steps as for previous configuration. Go to bin/Debug and select PeopleWcfService.dll and then PeopleWcfService.PersonWcfService. Save your configuration and close App.config

5) Start debugging. You will be able to see the new window (Test client – you can also prepare your own client, but it is the subject for another article) with your methods inside. Click at AddPerson() method and fill ItsName and ItsSurname properties. Then click Invoke button:



Go to GetPeople() method and select Invoke button. Now you can see [0] values:


That’s all. You have just created your first own WCF service with a Test client 🙂


One thought on “WCF service – how to start?

  1. Hey MJ-

    Your last post [WCF SERVICE – HOW TO START?] was freaking awesome. I have gone ahead and added your stuff to my Feedly account. Please keep me updated if you post anywhere else.

    Keep rocking –


Zostaw komentarz

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s