Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> WCF >> Creating “Hello World” WCF Application
Creating “Hello World” WCF Application
Creating “Hello World” WCF Application


by Awadhendra Tiwari on 8/11/2011 4:51:50 PM

Views: 6587       Comments: 0

Creating “Hello World” WCF Application

In this article we will learn that how to create a simple WCF application which is Hello World application.

Use .NET framework 4.0 and Visual Studio 2010 to create a WCF service application

1)      Start Visual Studio 2010.

2)      On the File Menu, point to new and then click on Project.

3)      In the New Project dialog box expand visual c# node and then select WCF template.

4)      From Project type window select WCF service application.

5)      Type Name and Location of project and then click on OK button.

Creating “Hello World” WCF Application

By performing these steps you can create a first WCF application with default template.

Now rename name of the file IService.svc to HelloWorld.svc and IService.cs to IHelloWorld.cs. This is not mandatory as I had done it on my sample you can put any name you want.

Creating ServiceContract

[ServiceContract] attribute is used to create a contract. For creating WCF application you need to create a ServiceContract. We use following codes to create a ServiceContract.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.Text;

 

namespace HelloWorldService

{

    [ServiceContract]          //This attribute is used to create a ServiceContract.

    public interface IHelloWorld            //Create a interface which defines contract

    {

        [OperationContract]   //Use [OperationContract] attribute to declare a method which will be accessiable via client.

        string GetMessage();

    }

 

}

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.Text;

 

namespace HelloWorldService

{

    //Implement IHelloWorld interface and override GetMessage() method displlay a message.

    public class HelloWorld : IHelloWorld

    {

        public string GetMessage()

        {

            return string.Format("Wow! You have successfully created first WCF application.");

        }

    }

}

 

Now build application and then execute it by pressing F5 key. By performing these steps you will see following dialog box which is known as WCF Test Client window.

Creating “Hello World” WCF Application

Now double click on getMessage() label followed by click on Invoke button and you get desired result.

Creating “Hello World” WCF Application

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 2717
Advertisement
MindStick DataConver
Advertise with Us
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.