Click here to Skip to main content
13,346,843 members (24,547 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 20 Jun 2011

Debug WCF REST Service.

, 21 Jun 2011
Rate this:
Please Sign up or sign in to vote.

In this article, we will see How to Debug WCF REST Service.

Prerequisite: Fiddler should be installed.

Refer to the attached sample WCF REST Service Project.

  • Add reference of "Microsoft.ServiceModel.Web.dll" from binary folder of Project and build the Project.
  • Host service in your IIS.
  • See how Service.svc is modified by viewing its Markup

<%@ ServiceHost Language="C#" Debug="true" Service="WCFRESTCODE.Service"  Factory="WCFRESTCODE.AppServiceHostFactory" %>

using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Microsoft.ServiceModel.Web;
    class AppServiceHostFactory : ServiceHostFactory
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            WebServiceHost2 webServiceHost2 = new WebServiceHost2(serviceType, true, baseAddresses);
            return webServiceHost2; 

Now we start with the actual debugging steps.

GET Method – Let’s see how to debug GET method.

In solution explorer, right click on your WCF REST Service Project. Then select "Start new instance" option under Debug menu.

This will open Service Instance in web browser like below:

You may get the below message on web page. Don’t bother and leave this page as it is open.

"Error Description: 'Resource does not exist'
This may be because an invalid URI or HTTP method was specified. Please see the service help page for constructing valid requests to the service."

Now open Fiddler. Select "GET" option from dropdown.

To debug method "GetUserDetails"[GET], copy below URL in Fiddler.


Why this format of URL?

* Because we have specified below format for "UriTemplate" Property of "WebInvoke" Attribute of "GetUserDetails" method.


Add below entry in "Request Headers" section.
Content-Type: text/xml

Now in Visual Studio, click on "Attach to Process…" option under "Debug" Menu.

Then select "Fiddler.exe" in "Available Processes" section and click on "Attach" button.

Now place debugger in "GetUserDetails" method.

And click on "Execute" button in Fiddler.

This will bring debugger pointer in your "GetUserDetails" method.

Now go to Fiddler and double click on your Service Request in Left Hand Panel.

You will get result of your Service Request as below:

POST Method

In solution Explorer, Right click on your WCF REST Service Project. Then select "Start new instance" option under Debug menu. As we did for GET method debugging steps.
Open Fiddler. We have to specify REST URL and its POST Web method which we want to debug.


Paste this URL in fiddler and select "POST" option from dropdown.

Add below text in "Request Headers" Tab.

Content-Type: text/xml

Now let’s specify input.

We are passing object of a class "UserInput" and we have specified "RequestFormat=WebMessageFormat.Xml" so that input will be like below:


In Visual Studio, click on "Attach to Process…" option under "Debug" Menu.

Then select "Fiddler.exe" and click on "Attach" button.

Now place debugger in "ValidateUser" method.

And then click on "Execute" button of Fiddler.

This will bring you in debugging mode of "ValidateUser" method.

Have a Happy WCF REST Service Programming and Debugging.


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


About the Author

Technical Lead
United States United States
Full Stack Technology Professional

Hands-on experience with -
. Asp.Net, MVC, C#, Ajax
. JavaScript, Jquery, AngularJS
. Xamarin
. SharePoint
. VBScript

Tested flavors of -
. Java, Perl, Python, NodeJS, Android, IOS(little bit)

You may also be interested in...


Comments and Discussions

AnswerSimple and effective solution Pin
Mukesh Salaria6-Jul-14 2:14
memberMukesh Salaria6-Jul-14 2:14 
GeneralRe: Simple and effective solution Pin
RaisKazi7-Jul-14 12:12
memberRaisKazi7-Jul-14 12:12 
Question[My vote of 1] Test project fails Pin
msdevtech12-Sep-13 8:10
membermsdevtech12-Sep-13 8:10 
AnswerRe: [My vote of 1] Test project fails Pin
RaisKazi17-Sep-13 7:54
memberRaisKazi17-Sep-13 7:54 
GeneralRe: [My vote of 1] Test project fails Pin
msdevtech17-Sep-13 14:10
membermsdevtech17-Sep-13 14:10 
GeneralMy vote of 3 Pin
Member 977551528-May-13 0:30
memberMember 977551528-May-13 0:30 
QuestionA small improvement Pin
bytebuster4633-Jun-12 7:00
memberbytebuster4633-Jun-12 7:00 
You actually don't need attaching to a process.
Just go to the WebService project Properties, Web -> Start Action -> Start External Program, and point to Fiddler or whatever.

Depending on the tool, you may add command-line arguments defining where to navigate to.

Then just F5.

P.S. Good article!
AnswerRe: A small improvement Pin
RaisKazi27-Aug-12 6:52
memberRaisKazi27-Aug-12 6:52 
GeneralReason for my vote of 5 good one Pin
coolsanjay21-Jun-11 5:13
membercoolsanjay21-Jun-11 5:13 
GeneralRe: Reason for my vote of 5good one Pin
RaisKazi27-Aug-12 6:53
memberRaisKazi27-Aug-12 6: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
Web04 | 2.8.180111.1 | Last Updated 21 Jun 2011
Article Copyright 2011 by RaisKazi
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid