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 920987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:48:16+00:00 2026-05-15T18:48:16+00:00

Is it possible to get a WCF service to return a ‘fault’ to the

  • 0

Is it possible to get a WCF service to return a ‘fault’ to the client? I’m led to believe this is possible when using SOAP, but I’d like to be returning JSON.

Ideally, the HTTP response code would be set to something to indicate that an error occured, and then details of the problem would be available in the JSON response.

Currently, I’m doing something like this:

[ServiceContract]
public class MyService
{
    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    [FaultContract(typeof(TestFault))]
    public MyResult MyMethod()
    {
        throw new FaultException<TestFault>(new TestFault("Message..."), "Reason...");
    }
}

Where TestFault looks like this:

[DataContract]
public class TestFault
{
    public TestFault(string message)
    {
        this.Message = message;
    }

    [DataMember]
    public string Message { get; set; }
}

There’s nothing particularly special in the service configuration at the moment.

This results in a ‘400 Bad Request’ response, with an HTML-formatted error. (When I includeExceptionDetailInFaults, I can see the ‘Reason…’ and details of the FaultException, but no details on the TestFault.)

The web service returns JSON ok when an Exception (or FaultException) isn’t being thrown.

Any suggestions..?

  • 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-15T18:48:17+00:00Added an answer on May 15, 2026 at 6:48 pm

    Edit: fixed link + added summary.

    You can find an explanation and a solution here

    To summarize the solution from the link, extend WebHttpBehavior and override AddServerErrorHandlers in order to add your own implementation of IErrorHandler. This implementation will extract the error from the service call and generate fault information.

    The linked article also shows how to write your own Service Host Factory that sets up this behavior.

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

Sidebar

Related Questions

I am trying to get a WCF service to return a List that contains
My AJAX-enabled WCF service returns JSON using this contract, [DataContract] public class JQGridContract {
I am trying to return some JSON from a WCF service. This service simply
How is it possible to return some kind of list from a WCF service,
I've written a WCF service and wonder if it somehow possible to not get
Possible Duplicate: Get the resolution of a jpeg image using C# and the .NET
Possible Duplicate: Get the IP Address of local computer Obtaining local IP address using
Possible Duplicate: Get a list of dates between two dates This is my sql:
I'm writing RESTful service with C#/wcf and need to put filters on GET. Like
I have developed WCF service which is internally using Entity framework for Database operation.

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.