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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:28:34+00:00 2026-05-25T03:28:34+00:00

I have a web service which takes a DateTime as a parameter. If a

  • 0

I have a web service which takes a DateTime as a parameter. If a user passes a value that is not of the correct format, .NET throws an exception before it ever goes into my Service function and therefore I cannot format some nice XML error response for the client.

For example:

[WebGet]
public IEnumerable<Statistics> GetStats(DateTime startDate)
{
    //.NET throws exception before I get here
    Statistician stats = new Statistician();
    return ServiceHelper.WebServiceWrapper(startDate, stats.GetCompanyStatistics);
}

My work around right now (which I strongly dislike) is:

[WebGet]
public IEnumerable<Statistics> GetStats(string startDate)
{
try
{
    DateTime date = Convert.ToDateTime(startDat);
}
catch
{
    throw new WebFaultException<Result>(new Result() { Title = "Error",
    Description = "startDate is not of a valid Date format" },
    System.Net.HttpStatusCode.BadRequest);
}
Statistician stats = new Statistician();
return ServiceHelper.WebServiceWrapper(startDate, stats.GetCompanyStatistics);
}

Is there something I am missing here? It seems there should be a cleaner way of doing this.

  • 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-25T03:28:34+00:00Added an answer on May 25, 2026 at 3:28 am

    The exception is the expected result, re: the parameter passed is not of type DateTime. This would be the same result if an array were passed as a parameter that was expecting an int.

    Your solution of creating another signature for the method is certainly viable. The method accepts a string as a parameter, attempts to parse the value as a date, if it succeeds, then call the method that is expecting the DateTime as a parameter.

    Example

    [WebGet]
    public IEnumerable<Statistics> GetStats( DateTime startDate )
    {
        var stats = new Statistician();
        return ServiceHelper.WebServiceWrapper(startDate, stats.GetCompanyStatistics);
    }
    
    [WebGet]
    public IEnumerable<Statistics> GetStats( string startDate )
    {
      DateTime dt;
      if ( DateTime.TryParse( startDate, out dt) )
      {
        return GetStats( dt );
      }
    
      throw new WebFaultException<Result>(new Result() { Title = "Error",
        Description = "startDate is not of a valid Date format" },
        System.Net.HttpStatusCode.BadRequest);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple HelloWorld web service. Which takes an ArrayList as parameter.
I have a java client that is calling a web service operation which takes
I have a .net web service that takes some xml data. From within the
I have a web service which has a generic function that returns a dataset
I have a .NET web service which is publically accessible since it needs to
I have a restful web service which can deal with DTOs in json format
I have a web service to which users upload python scripts that are run
We have developed a web application which consumes a web service. The user will
We have a simple ASP.Net WCF Ajax enabled web service which is called via
I have an Ajax request to a web service that typically takes 30-60 seconds

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.