2

Given the following ASP.NET code:

[System.Web.Script.Services.ScriptService]
public class Quotes : System.Web.Services.WebService
{
    [WebMethod]
    public void Calculate(int param1, int? param2)
    {

etc.. How can I pass a null value to param2? If I don't pass the parameter at all, or I pass undefined, my error handler fires with "Invalid web service call, missing value for parameter: 'param2'".

Sprintstar
  • 7,938
  • 5
  • 38
  • 51

2 Answers2

2

Ok I was being stupid. I simply pass null!

Why is null an object and what's the difference between null and undefined?

Community
  • 1
  • 1
Sprintstar
  • 7,938
  • 5
  • 38
  • 51
1

If you're using C# 4.0 you could set a default value on the parameter.

ie

[WebMethod]
    public void Calculate(int param1, int? param2 = null)
    {...}
Dave
  • 2,552
  • 5
  • 25
  • 30