Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4321910
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:48:23+00:00 2026-05-21T08:48:23+00:00

I’m having a mind blowing problem using WCF 4.0 RESTful service. I am trying

  • 0

I’m having a mind blowing problem using WCF 4.0 RESTful service. I am trying to make a rest service that will return, in case of an error, a xml document describing the problem
ex :

    <ErrorHandler>
        <cause>Resource not  available</cause>
        <errorCode>111103</errorCode>
    </ErrorHandler>

In order to make this i’ve created a default REST service using the template provided by visual studio
Here is my service Class :

public class Service1
    {
        // TODO: Implement the collection resource that will contain the SampleItem instances

        [WebGet(UriTemplate = "")]        
        public List<SampleItem> GetCollection()
        {
            // TODO: Replace the current implementation to return a collection of SampleItem instances\
           // throw new WebException("lala");
           throw new WebFaultException<ErrorHandler>(new ErrorHandler { cause = "Resource not  available", errorCode = 100 }, System.Net.HttpStatusCode.NotFound);
            //return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
        }

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public SampleItem Create(SampleItem instance)
        {
            // TODO: Add the new instance of SampleItem to the collection           
            return new SampleItem() { Id = 3, StringValue = "59" };

        }

        [WebGet(UriTemplate = "{id}")]
        public SampleItem Get(string id)
        {
            // TODO: Return the instance of SampleItem with the given id
            throw new NotImplementedException();
        }

        [WebInvoke(UriTemplate = "{id}", Method = "PUT")]
        public SampleItem Update(string id, SampleItem instance)
        {
            // TODO: Update the given instance of SampleItem in the collection
            throw new NotImplementedException();
        }

        [WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
        public void Delete(string id)
        {
            // TODO: Remove the instance of SampleItem with the given id from the collection
            throw new NotImplementedException();
        }

    }
}

As you can see from the code above i am throwing a WebFaultException in the GetCollection method. that should put in the body of the response a “ErrorHandler” object.
Here is how my ErrorHandler class looks like :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;

namespace WcfRestService1
{
    [DataContract]
    public class ErrorHandler
    {
        [DataMember]
        public int errorCode { get; set; }
        [DataMember]
        public string cause { get; set; }

    }
}

The crazy thing is that this thing works but it down’t :)). What i’m trying to say is that visual studio is giving me an error saying that the WebFaultException is not caught by the user code 😐 and it suspends my app. If i press continue everything works as it should.
Here are some pictures describing my problem:

First step in fiddler :
First Step

Next Visual Studio’s error: Visual Studio Error

Finally After pressing continue everything works :

It makes no sense to me and i have no idea why this thing is happening and how to fix it :P. I’ve searched the web for days trying to find a solution with no luck. I’m using Visual Studio 2010 Ultimate

Best Regards 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:48:23+00:00Added an answer on May 21, 2026 at 8:48 am

    Nothing is wrong here. You are debugging, an exception is thrown, it breaks, you continue and it works as it should.

    I suspect you have set the exception handling option (Ctrl+Alt+E) to break when exceptions are thrown. (“Thrown” in the options) This will cause break whenever exception is thrown regardless it is handled.

    Exceptions that are thrown in WCF operations will be handled by the WCF runtime and if they are faults, they will be sent back as such so that channel is not faulted.

    Now with regard to sending back an XML, you can just send string representation of the XML using WebFaultException<string>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.