Step by step process to develop a simple WCF service

Madhu.b.rokkam
Posted by in WCF category on for Beginner level | Points: 250 | Views : 99945 red flag
Rating: 5 out of 5  
 2 vote(s)

This is my first article and thru this and all my comming articles I would like to help all the beginners to understand and develop WCF services with ease.

Introduction

WCF is one of the best programming models supplied by Microsoft for building more secure, reliable, interoperable system for building, configuring and deploying network-distributed services. WCF being a unified programming model that has features of a Web Service, features of Remoting, and MSMQ and others.

In this first article we will discuss Step by step on how we to create a simple WCF service.

1. Start visual studio and select a WCF service application template, Name the project as WcfService1, choose a location to save this project.

2. Remove all the predefined generated code from IService1 file and type as shown in the figure to create a Greeting method. 


3. Now open the Service1.svc.cs file and implement the interface method.

4. Check the web.config file for the changes, comments are seft explanatory.

5.Build and run the service.

6. The WCF Service is ready and now we need to create a client application to test our service.

7. Add a new console application project to the solution name it as SampleClient



8. Now right click on the references and click on ServiceReference, Specify the address to locate the service and Set the namespace Click Ok.



9. Create an object of the proxy client class and call the Greeting method as shown.

10. Check the app.config file for configuration changes

11. Build and execute the application

Thats it ... its done.

Conclusion

You all saw how simple it is to create a simple WCF and test it using a console client application. In my next article I will explain you how to test the WCF service without creating any client application.

Untill then Happy Coding... 

Page copy protected against web site content infringement by Copyscape

About the Author

Madhu.b.rokkam
Full Name: Madhu Rokkam
Member Level: Bronze
Member Status: Member,MVP
Member Since: 1/13/2011 3:13:20 PM
Country: India
Thanks and Regards Madhu
http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Posted by: Vuyiswamb on: 2/13/2011 | Points: 25
Good article thanks for Sharing.
Posted by: Karthikanbarasan on: 2/13/2011 | Points: 25
good article... but provide the sample code as well...
Posted by: Madhu.b.rokkam on: 2/14/2011 | Points: 25
Hi ALl,

Dont think otherwise, The reason why I have not provided the sample code is because I want all to do this task of their own so that they can practice rather than just downloading the article and watching what has been done. But If you need I will definitely put the code also into this.

Let me know if you need this ....


Posted by: Karthikanbarasan on: 2/14/2011 | Points: 25
Madhu,

Images are very small and its not self explanatory esp in this section below

4. Check the web.config file for the changes, comments are seft explanatory.

Please update with more explanation....
Posted by: Madhu.b.rokkam on: 2/14/2011 | Points: 25
Sure Karthik,

I will add few more details on to this. Thanks for your comments
Posted by: Karthikanbarasan on: 2/14/2011 | Points: 25
Sure Madhu!!!
Posted by: Klbaiju on: 2/14/2011 | Points: 25
Hi madhu iam getting following error.
how to solve this.

Regards
Baiju

Directory Listing -- /

--------------------------------------------------------------------------------

Monday, February 14, 2011 02:52 PM <dir> App_Data
Monday, February 14, 2011 02:54 PM <dir> bin
Monday, February 14, 2011 02:52 PM <dir> obj
Monday, February 14, 2011 02:52 PM <dir> Properties
Monday, February 14, 2011 02:54 PM 1,380 IService1.cs
Monday, February 14, 2011 02:52 PM 108 Service1.svc
Monday, February 14, 2011 02:54 PM 948 Service1.svc.cs
Monday, February 14, 2011 02:52 PM 4,223 WcfService4.csproj
Monday, February 14, 2011 02:52 PM 1,359 WcfService4.csproj.user
Monday, February 14, 2011 02:54 PM 9,007 Web.config


--------------------------------------------------------------------------------
Version Information: ASP.NET Development Server 9.0.0.0
Posted by: rameshmandapelly-7781 on: 2/14/2011 | Points: 25
hai madhu ,


we need sample code files can provide downloads
Posted by: Madhu.b.rokkam on: 2/14/2011 | Points: 25
Hi KLBaiju

Just you need to select the Service1.svc as the startup file.

that will solve your problem.
Posted by: Madhu.b.rokkam on: 2/14/2011 | Points: 25
Hi Ramesh,

Sure I will upload the source code today evening may be you can check tomorrow.
Posted by: Klbaiju on: 2/16/2011 | Points: 25
Hi,
thanks for ur suggestion.my application is working fine.
I also add a webapplication instead of cosole application.
and wrote this
protected void Page_Load(object sender, EventArgs e)
{
ProxyService.Service1Client Client = new ProxyService.Service1Client();
Response.Write(Client.Greeting("Baiju"));
}
this also working. is it correct method.

Regards
K L BAIJU
Posted by: Samir on: 9/3/2012 | Points: 25
good one
Posted by: Casper01 on: 11/24/2012 | Points: 25
Hi,
I followed instruction as above but getting following error:-
The type 'WcfService1.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type 'WcfService1.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

Please Help.

Regards
Casper
Posted by: Casper01 on: 11/24/2012 | Points: 25
I am now getting -->
Metadata publishing for this service is currently disabled.

But in my web.config it is enabled.

<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name=" WCFSample1.Service1" behaviorConfiguration="WCFSample1.Service1Behavior">
<endpoint address="http://localhost:2735/Service1.svc" binding="wsHttpBinding" contract="WCFSample1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFSample1.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

Many thanks for your help.

Regards
Casper

Login to post response

Comment using Facebook(Author doesn't get notification)