Exercise 1: Service without Configuration

In WCF 4 you can create a service without any configuration at all. In this exercise, you will create a working WCF service with no configuration.

Task 1 – Creating the Web Site

  1. Start Microsoft Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010.
  2. Create a new Empty ASP.NET Web Application.

    Setting

    Value

    Language

    Visual C# or Visual Basic

    Target Framework

    .NET Framework 4

    Installed Templates

    Web

    Template

    ASP.NET Empty Web Application

    Name

    WCF4Configuration

    Location

    Source\Ex1-NoConfig\Begin

    Solution Name

    WCF4Configuration

    Figure 1

    Create a new Empty ASP.NET Web Application – C#

    Figure 2

    Create a new Empty ASP.NET Web Application – Visual Basic

Task 2 – Creating the WCF Service

  1. Right-click the WCF4Configuration web site, point to Add and select NewItem.

    Setting

    Value

    Language

    Visual C# or Visual Basic

    Installed Templates

    Web

    Template

    WCF Service

    Name

    EchoService.svc

    Figure 3

    Create a new service named EchoService.svc – C#

    Figure 4

    Create a new service named EchoService.svc – Visual Basic

  2. Open IEchoService and modify it as shown in the following code.

    (Code Snippet - What is new in WCF4 Lab - IEchoService Interface CSharp)

    C#

    [ServiceContract] public interface IEchoService { [OperationContract] string Echo(string message); }

    (Code Snippet - What is new in WCF4 Lab - IEchoService Interface VB)

    Visual Basic

    <ServiceContract()> Public Interface IEchoService <OperationContract()> Function Echo(ByVal message As String) As String End Interface
    FakePre-fee3e987216b4315a4ba9f33735f9be0-565d26f8a7c2433ea453a62fba5110c6
    

  3. Right-click EchoService.svc file, and select View Code.
  4. Add the following namespace

    C#

    using System.Globalization;

    Visual Basic

    Imports System.Globalization

  5. Delete the DoWork method and modify EchoService to implement the Echo operation as shown.

    (Code Snippet - What is new in WCF4 Lab - Echo method CSharp)

    C#

    public string Echo(string message) { if (string.IsNullOrEmpty(message)) throw new ArgumentNullException("message"); return string.Format(CultureInfo.InvariantCulture, "Echo: {0}", message); }

    (Code Snippet - What is new in WCF4 Lab - Echo method VB)

    Visual Basic

    Public Function Echo(ByVal message As String) As String Implements IEchoService.Echo If (String.IsNullOrEmpty(message)) Then Throw New ArgumentNullException("message") End If Return String.Format(CultureInfo.InvariantCulture, "Echo: {0}", message) End Function

  6. Open Web.config and comment out the entire <system.serviceModel> section by selecting it and pressing CTRL+K,CTRL+C

Next Step

Exercise 1: Verification