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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:16:04+00:00 2026-05-28T17:16:04+00:00

1. Required parameter In the following example URI definition [WebGet(UriTemplate = GetData?value={value})] [OperationContract] string

  • 0

1. Required parameter

In the following example URI definition

[WebGet(UriTemplate = "GetData?value={value}")]
[OperationContract]
string GetData(int value);
{
    return string.Format("You entered: {0}, value);
}

the “value” parameter is optional by default, and if I don’t pass it (call to http://baseAddress/GetData), the variable is filled with zero.

Is there any easy way to make this parameter required, maybe an attribute? The only way I found is to manually check WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["value"] != null.

2. HTTP 400 on wrong format

Another thing I hate is that HTTP 500 is returned for /GetData?value=emptyOrAnythingThatIsNotAnInteger. Can I return HTTP 400 instead? Of course without changing the type to string and checking everything manually.

  • 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-28T17:16:05+00:00Added an answer on May 28, 2026 at 5:16 pm

    The reason for a 500 error when you pass something other than integer is that WCF tries to parse the value passed into an integer and at this stage your request is already received and has been started for processing by the service.

    You get a 400 error only when the message is on the channel and WCF doesn’t understand the message format of the incoming message and that it needs to convert as specified by the service.

    In order to inspect your value and return a 400 error try to use “MessageInspectors” where you have methods like “AfterReceiveRequest” by IDispatcherMessageInspector. Some info on Message inspectors can be found here.

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

Sidebar

Related Questions

In my application I have a string parameter called shop that is required in
Consider the following code: int SomeField; void Foo([Pure] Func<int, object> getData) { Contract.Requires(getData !=
I'm have the following URL : www.example.com?arg1=foobar I want to get the arg1 value.
In the following example, the ScriptFile parameter is marked with an @Valid annotation. What
The documentation of jQuery.animate states that The only required parameter is a map of
I'm having problems getting the form parameters in the following Compojure example: (ns hello-world
I have the following class definition, written in C++, residing in it's own header
I try to implement a table function by following Tony Andrews example . But
I'm wondering what exactly the status parameter in the pthread_join is for int pthread_join(pthread_t
I have the following piece of code, as an example dec_proxy attempts to reverse

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.