In my previous post, a simple wcf service, i showed how to make a WCF service that can return an array of strings.
In this post i will show you how to make a client in a regular ASP.NET website that can question this service and display the returned value on a page.
Start off by creating a new Website:

I selected “ASP.NET Web Site”, picked .NET Framework 3.5 and i gave the thing a custom name.
Visual Studio will now create the files we typically need in a .NET website. Let’s just leave that now for what it is and make the reference to our service allready.
Adding a reference to the WCF Service
So in order to use our service in our website we will have to make some sort of reference to it. Luckily, Visual Studio can do nearly all the work for us.
Make sure your service is up and running (either on your localhost or somewhere else). You’ll need to know the address on which it is running so if you’ve got the service running on your local computer you might as well look in the WCF Test Client to see the exact url of the service.
In our web project right click the project and choose “”Add Service Reference”:

Now with the Service reference dialog open we can input the address of our service and add it to our project. Notice that by doing this our IService contract is being used to communicate the functions of our service:

Just click “Ok” and Visual Studio will take care of the rest. I will explain in a future post what exactly the files are that are being constructed since this is supposed to be a brief demo.
Databinding from the Service to a gridview
We’re nearly done.
Drag a gridview into the markup of your default.aspx and put AutoGenerateColumns on “True”. This is merely because i’m too lazy to create the colums myself.
Give your gridview and appropriate name like BrandsGridView.
In the codebehind we can now implement this code to get the info from the service and databind it:
protected void Page_Load(object sender, EventArgs e)
{
string[] brandsList;
ServiceReference1.CarServiceClient wcfService = new ServiceReference1.CarServiceClient();
try{
//i added an integer parameter to the get method so i can later use it to select the brands from a certain collection
brandsList = wcfService.GetBrands(0);
wcfService.Close(); //don't forget this!
}
catch (Exception)
{
wcfService.Abort();
}
BrandGridView.DataSource = brandsList;
BrandGridView.DataBind();
}
And when we run this website (F5) all should work out just fine:

Next stop on my WCF journey will be DataContracts; juggeling with object from service to client and vice versa.