Click here to Skip to main content
13,514,056 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked
Posted 31 Mar 2012

Design the WCF Service without Implementing Interface

, 31 Mar 2012
Rate this:
Please Sign up or sign in to vote.
Design the WCF service without implementing interface


I will demonstrate how to create the WCF service without using interface. The general process to create the WCF service is to create interface and implement it into the class. This is best practice which is defined in the SOA model but similar to Web Service, we can create the WCF without implementing the interface.

In this WCF demonstration, you will see that from the code and implementation perspective, both web service and WCF are similar except WCF has the entire configuration detail in web.config which has almost complete control on runtime characteristics of a service without forcing a change in code.

Using the Code

In this demonstration, I use only one class and define WCF method inside this class. Also, instead of Interface name specifying the Class name in config file end point, I show the Service1.cs file code which has Service1 class and DisplayName WCF method.

using System;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace WCFServiceWithOutUsingInterface
    // NOTE: Not implementing the Interface and using interface attribute directly to class
    [ServiceContract ]
    public class Service1 
        public string DisplayName(String value)
            return string.Format("You Name is : {0}", value);

I am showing the Web.config file where instead of Interface name, I specify the Class name as Contract name in the end point .

<?xml version="1.0"?>
    <compilation debug="true" targetFramework="4.0" />
      <service name ="WCFServiceWithOutUsingInterface"  >
        <endpoint contract ="Service1" binding="wsHttpBinding"></endpoint> 
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>

Note about the Attached Code contains the WCFServiceWithOutUsingInterface.sln which has WCF service and consumes WCF service projects.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Umesh Khandelwal
Technical Lead
United States United States
Working on Microsoft Technologies and Cloud computing.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
stooboo9-Aug-12 10:48
memberstooboo9-Aug-12 10:48 
GeneralRe: My vote of 1 Pin
Umesh Khandelwal10-Aug-12 3:35
memberUmesh Khandelwal10-Aug-12 3:35 
GeneralMy vote of 5 Pin
Member 89431767-May-12 23:59
memberMember 89431767-May-12 23:59 
Questionmy vote 5 Pin
beqiraj2542-Apr-12 3:07
memberbeqiraj2542-Apr-12 3:07 
Generalis there any benefit of creating a WCF service without using Interface? Pin
nit_singh1-Apr-12 1:46
membernit_singh1-Apr-12 1:46 
GeneralRe: is there any benefit of creating a WCF service without using Interface? Pin
Umesh Khandelwal1-Apr-12 1:53
memberUmesh Khandelwal1-Apr-12 1:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180417.1 | Last Updated 1 Apr 2012
Article Copyright 2012 by Umesh Khandelwal
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid