In my earlier articles, i have explained how to create web service in C#.net and then how to publish the web service in IIS & how to consume web service.
To test this service, you will need to create a client and use it to call the service. Click here to know how to consume the WCF web service using client application. There is another way to test the web service. Click here to know how to test WCF test web service using wcftestclient.
One most important thing is to logg the WCF events and for messages for debugging purpose. Read more on how to enable WCF tracing and MessageLogging.
I hope you enjoyed the article. Could you please share the article on your social media? Thank you!
Following few articles might be of your interest -
1) How to self host the WCF service?
2) How to consume WCF service in ASP.net?
3) How to host WCF service in IIS?
4) How to enable WCF tracking and MessageLogging?
This C# tutorial explains how to create a WCF web service in visual studio 2010. The complete list of WCF tutorials is here.
Before proceeding make sure following things are installed in your system –
i) Visual Studio 2010 (C#)
ii) Windows SDK’s
iii) IIS Windows features
a) IIS Metabase and IIS 6 configuration utility
b) IIS management console
c) ASP.net
1) To create a new WCF service application project, go to menu File -> New -> Project. Then select WCF under Visual C# installed templates and then select WCF Service Application.
![]() |
| Creating a new WCF web service application |
Here I am giving the project name as “MyFirstWcfWebService”. Click on Ok button.
2) If you look at the Solution Explorer, you will get following two code files added in web service project.
i) Service1.svc
ii) IService1.cs. – This is an Interface. We call this interface as ServiceContract.
You will get following auto generated code in Service1.svc.cs file –
![]() |
| Service1.svc.cs - Auto Generated code |
Here, GetData and GetDataUsingDataContract are the web methods. There is no harm in removing these two methods. I am keeping these two methods as it is and adding another method that accepts string and returns a wel come message.
3) Add following code below GetDataUsingDataContract method –
public String WelComeMessage(String name)
{
return String.Format("{0}, Welcome to http://a1ashiish-csharp.blogspot.com", name);
}
4) Now open, IService1.cs from solution explorer. You will get following auto generated code –
![]() |
| Iservice1.cs - Auto Generated code |
Here, we call Interface as ServiceContract and the corresponding methods are called as OperationContract.
5) Now, we need to add OperationContract to our newly created Web method i.e WelComeMessage. Add following code below GetDataUsingDataContract –
[OperationContract]
String WelComeMessage(String name);
Now, the final code will looks like -
![]() |
| Final Code after writing OperationContract for WelComeMessage web method |
6) Your web service is ready. Now execute the web service by hitting F5 button. It will open following page.
![]() |
| Directory Listing of WCF web service. |
7) Click on Service1.svc. It will open following page.
![]() |
One most important thing is to logg the WCF events and for messages for debugging purpose. Read more on how to enable WCF tracing and MessageLogging.
I hope you enjoyed the article. Could you please share the article on your social media? Thank you!
Following few articles might be of your interest -
1) How to self host the WCF service?
2) How to consume WCF service in ASP.net?
3) How to host WCF service in IIS?
4) How to enable WCF tracking and MessageLogging?
Sharing is Caring »»
|
|
|
Tweet |





