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

  • Home
  • SEARCH
  • 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 4029866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:23:57+00:00 2026-05-20T11:23:57+00:00

I have created a REST service using WCF for communicating with BLL/DAL from UI.

  • 0

I have created a REST service using WCF for communicating with BLL/DAL from UI. Now, I would like to implement Exception Handling through some globalize way in REST. I am using HTTPClient to communicate with REST from client. The following are the ways, I have implemented exception handling:

Approach 1:

OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
response.StatusCode = System.Net.HttpStatusCode.Unauthorized;
response.StatusDescription = ex.Message;
success = false;

Approach 2:

throw new WebProtocolException(HttpStatusCode.NotFound, ex.Message, null);

but somehow I am not able to catch them in the client side. Kindly suggest some pointers in order to handle exceptions raised by service globally.


I am throwing WebProtocolException (Approach 2) along with error code and error message from the service to UI in order to notify users about the exception. I am able to receive the error code in UI side but not getting error message or detail.

Then I created another service (having .svc extension) and added following line to the service’s markup: “Factory=’Microsoft.ServiceModel.Web.WebServiceHost2Factory'”. Now, I am able to receive the error message along with error code on client side (UI).

Can anybody let me know how to use the WebServiceHost2Factory method in my existing service which is a class file instead of .svc file?

Any suggestions will be highly appreciated. Thanks

  • 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-20T11:23:58+00:00Added an answer on May 20, 2026 at 11:23 am

    HttpClient does not throw exceptions when a response comes back that is not “successful”. If you really want exceptions to be thrown on the client side, then call

    response.EnsureResponseIsSuccessful();
    

    Otherwise, just check the status code on the client and decide what to do based on that value.

    You cannot throw exceptions on the server and expect the exceptions to be propagated to the client. HTTP does not have any notion of exception.

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

Sidebar

Related Questions

I created a new wcf rest service using .net 4. I have created a
I have created a REST web service using WCF and use HTTP Post Method.
I have a WCF rest service. I created it using 4.0 rest service application,
I have ASP MVC 3 application. I created WCF REST JSON Service and added
I have created a MVC 3 WCF Rest project using the tutorial described here
I have just created my first rest service using apicontroller. I am using it
I have created a WCF REST style service in my project. In development I
I have a WFC Data Service using OData v3. Following REST specification I created
I have a serializable dictionary that I created for a WCF REST web service
I have a REStful WCF web service (using a substantially modified WCF Rest Starter

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.