Hello all
Today I will show how to consume a WCF service. To go through this before, I have created a WCF service [ Creating WCF Service ] , which I will consume for my project in this article. Consuming WCF Service is as simple as consuming a simple webservice through Visual Studio 2008.
First I am taking an empty Web project named ConsumedWCF.
Now I will add a service reference which I have created before [ Creating WCF Service ] in this ConsumedWCF project as bellow:
In my previously created WCF service I have got a URL for my service "http://localhost:49530/DataService.svc?wsdl", I have pasted the URL in the Address box. One thing we should have to remember that,to consume the service we have to run that service during development.
Now I will consume the service from my Default.aspx . My Default.aspx.cs content is as bellow:
using System; using ConsumeWCF.ServiceReference1; namespace ConsumeWCF { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DataServiceClient cl = new DataServiceClient(); Response.Write( cl.GetUserDataFromService().UserName); Response.Write("<br />"); Response.Write(cl.GetUserDataFromService().UserLocation); Response.Write("<br />"); Response.Write( cl.GetUserRestrictionFromService("1")); Response.Write("<br />"); Response.Write(cl.GetUserRestrictionFromService("23")); } } }
The above code will print the values which we have consumed form the WCF service.
Thanks
That’s all for the day.
BYE






Sohan says:
Simple and useful. A post on consuming WCF service using ajax/asp.net ajax will be interesting to read.
April 15, 2009, 8:11 amtanvirdotnet says:
Thanks Sohan vi. I will go through it in near future (in my blog).
April 17, 2009, 4:28 amAshrafuzzaman says:
Dot net makes some thing very easy to use where it was previously difficult.
May 3, 2009, 10:52 am