Pass optional Date param into a Web Api 2 Web service

Hi there,

I've written a simple IOS app that lists sender details, using MS Web API 2 framework. I need to be able to pass in an optional date param, but i'm having issues. This is the controller:

 [Authorize]
    [RoutePrefix("api/summary")]
    public class SummaryController : ApiController
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="displayLength"></param>
        /// <param name="displayStart"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
      
        [Route("{sender}/{displayLength}/{displayStart}")]
        public HttpResponseMessage GetSenderMessages(string sender, int? displayLength, int? displayStart,
            [FromUri] DateTime from, 
            [FromUri] DateTime to,
          )
        {}}

Open in new window


When I call this using:

http://locahost/api/summary/7/0/from,to

I keep getting invalid signature -  my call is incorrect. What am I doing wrong?
LVL 1
Wayne AthertonProduct Analyst Financial Messaging LondonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
You need to provide defaults for the values that are default. The official documentation provides examples of this.
Wayne AthertonProduct Analyst Financial Messaging LondonAuthor Commented:
Kaufmed,

Thanks for the post - so after reading this is it true to say that you can't pass nothing. My method basically looks for a date value and if one is received the. The result set is filtered accordingly. If no date then it does something else.

Therefore, I need to be able to not default to a specific value for the From / To parameters.
käµfm³d 👽Commented:
So make them nullable, and set the default value to null.

e.g.

public HttpResponseMessage GetSenderMessages(string sender, int? displayLength, int? displayStart,
            [FromUri] DateTime? from = null, 
            [FromUri] DateTime? to = null,
          )

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Services

From novice to tech pro — start learning today.