4 Replies - 3047 Views - Last Post: 14 September 2011 - 12:04 PM

#1 antarr.byrd  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 247
  • Joined: 30-August 09

Using optional Parameter

Posted 14 September 2011 - 11:07 AM

I'm trying to you use a web service with my MVC3 controller. This service has an optional parameter, such as

Service.GetObject(int id, DateTime? date)


But when I try to call it will a null value , like

Service.GetObject(12345, null)


I get this error.

Quote

$exception {"Object cannot be cast from DBNull to other types."} System.Exception {System.ServiceModel.FaultException}


Please Help if you can. Thank you!

This post has been edited by tlhIn`toq: 14 September 2011 - 11:40 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Using optional Parameter

#2 tlhIn`toq  Icon User is online

  • Closing in on 5,000
  • member icon

Reputation: 4926
  • View blog
  • Posts: 10,460
  • Joined: 02-June 10

Re: Using optional Parameter

Posted 14 September 2011 - 11:14 AM

If it is optional, then just don't include it. That what they show on the MSDN. Amazing what you find out by reading the documentation.

Service.GetOject(12345);

Optional parameters on the MSDN

This post has been edited by tlhIn`toq: 14 September 2011 - 11:14 AM

Was This Post Helpful? 0
  • +
  • -

#3 antarr.byrd  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 247
  • Joined: 30-August 09

Re: Using optional Parameter

Posted 14 September 2011 - 11:21 AM

View PosttlhIn`toq, on 14 September 2011 - 12:14 PM, said:

If it is optional, then just don't include it. That what they show on the MSDN. Amazing what you find out by reading the documentation.

Service.GetOject(12345);

Optional parameters on the MSDN



When I try that
Service.GetObject(12345);
I get a syntax error stating that I'm trying to call with 1 parameter but 2 is expected.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Closing in on 5,000
  • member icon

Reputation: 4926
  • View blog
  • Posts: 10,460
  • Joined: 02-June 10

Re: Using optional Parameter

Posted 14 September 2011 - 11:45 AM

Then we aren't talking about an 'optional parameter' as defined in .NET and how I for one would expect it to be used in C# (where you posted).

I'm afraid you might be forced into reading the documentation for the service and see what the service creator definse as an optional parameter and what their documentation shows as an example of using it.

Since this is all about ASP (unless by MVC3 you mean Marvel v. CapCon 3) this entire thread is probably not in the best place it could be for answers.

Moved to ASP|MVC forum
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 3792
  • View blog
  • Posts: 6,387
  • Joined: 08-June 10

Re: Using optional Parameter

Posted 14 September 2011 - 12:04 PM

Are you sure the parameter is optional? Did you write it yourself?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1