title: How to build web service/web api with optional parameters in C#
body: <p>I'm building a web API using web service.
  Users may use it like this:
  <code>http://www.example.com/example.asmx/hello?param1=str&amp;param2=str</code></p>
  
  <p>or:</p>
  
  <p><code>http://www.example.com/example.asmx/hello?param1=str</code> .</p>
  
  <p>I want to make param1 required while param2 optional.But my code below always throws an exception that says missing values for parameters when I try to call <code>http://www.example.com/example.asmx/hello?param1=str</code>. It works fine with <code>http://www.example.com/example.asmx/hello?param1=str&amp;param2=str</code>.</p>
  
  <pre><code>[WebMethod]
  public string hello(int param1, int param2 = 0)
  {
      return "hello!";
  }
  </code></pre>
  
  <p>Is there any way to fix it? If not, what techniques can I use to build a web API that accept optional parameters which is very common in public APIs. I'm a newbie so I don't know if web service is a good choice for building web APIs. Any help is appreciated.</p>