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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:50:33+00:00 2026-06-02T04:50:33+00:00

In my WCF REST service, there is a method GetUser(username), which will throw new

  • 0

In my WCF REST service, there is a method GetUser(username), which will

throw new WebFaultException<string>("there is no this user", HttpStatusCode.NotFound);

In my asp.net client, I want to catch above exception and show “there is no this user” on a label. But when I try coding as follow:

MyServiceClient client = new MyServiceClient;
try
{
    client.GetUser(username);
}
catch (Exception ex)
{
    Label.Text = ex.Message;
}

It turns out show the message “NotFound” instead of “there is no this user”.

How can i do to show the message “there is no this user”?


20/4

In my REST service:

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "{username}")]
void GetUser(username);

.svc class :

 public void GetUser(username)
    {
        try
        {
            Membership.GetUser(username);
            WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.OK;
        }
        catch (Exception ex)
        {
            throw new WebFaultException<string>("there is no this user", HttpStatusCode.NotFound);
        }
    }
  • 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-06-02T04:50:34+00:00Added an answer on June 2, 2026 at 4:50 am

    If you look into the documentation, it’s obvious that you should be showing the Detail, not the Message. Your line should be:

    MyServiceClient client = new MyServiceClient;
    try
    {
        client.GetUser(username);
    }
    catch (FaultException<string> ex)
    {
        var webFaultException = ex as WebFaultException<string>;
        if (webFaultException == null)
        {
           // this shouldn't happen, so bubble-up the error (or wrap it in another exception so you know that it's explicitly failed here.
           rethrow;
        }
        else
        {
          Label.Text = webFaultException.Detail;
        }
    }
    

    EDIT: changed exception type

    Also, you should be catching the specific exception (WebFaultException<string>) that you’re interested in, not any-old exception that happens to be thrown. Especially, as you’ll only have the Detail on the WebFaultException<string> type, it’s not on Exception.

    See the WebFaultException Class

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

Sidebar

Related Questions

I have a WCF-REST service with one method which returns a string: [ServiceContract] public
I have a WCF REST Service which accepts a JSON string One of the
Is there a way in a WCF Rest Service implementation to require one method
There is a WCF REST service hosted in Windows Service or in command line
So I have wcf rest service which succesfuly runs from a console app, if
I am attempting to get the WCF Rest Service Template 40 (CS) which is
I have a WCF Rest service: [WebHelp(Comment = Sample description for GetData)] [WebInvoke(Method=POST, UriTemplate
We're in the process of developing a WCF REST web service which just receives
Is there a clean way to expose a WCF REST service that requires basic
We are currently implementing a new WCF REST service in IIS for our site

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.