title: How can I call two GET Web API REST methods, the first to get the count of records that the second one will return?
body: <p>I know this is kludgy, but in my existing Web API client code, the way I stop reading records is when my call to webRequest.GetResponse() crashes on reading and finding none, and eating the exception (I'm reading a "block/chunk" at a time, due to the bandwidth limitations of the handheld device which calls the Web API REST method).</p>
  
  <p>As my conscience (so to speak) was bothering me about doing it this way (but it works!), I thought maybe I could first get the count of records and use that knowledge to preclude reading beyond the pale/edge of the world, thus avoiding the exception.</p>
  
  <p>However, as can be seen here: <a href="https://stackoverflow.com/questions/19963238/why-is-my-web-api-routing-being-re-routed-falsely-routed">Why is my Web API routing being re-routed / falsely routed?</a>, I'm finding no success in trying to access multiple GET methods - I could only get the desired GET method to be called by eliminating the other one!</p>
  
  <p>My existing client code is:</p>
  
  <pre><code>private void buttonGetInvItemsInBlocks_Click(object sender, EventArgs e)
  {
      string formatargready_uri = "http://localhost:28642/api/inventoryItems/{0}/{1}";
      // Cannot start with String.Empty or a blank string (" ") assigned to lastIDFetched; they both fail for some reason - Controller method is not even called. Seems like a bug in Web API to me...
      string lastIDFetched = "0"; 
      const int RECORDS_TO_FETCH = 100; 
      bool moreRecordsExist = true;
  
      try
      {
          while (moreRecordsExist) 
          {
              formatargready_uri = string.Format("http://localhost:28642/api/InventoryItems/{0}/{1}", lastIDFetched, RECORDS_TO_FETCH);
              var webRequest = (HttpWebRequest)WebRequest.Create(formatargready_uri); 
              webRequest.Method = "GET";
              var webResponse = (HttpWebResponse)webRequest.GetResponse(); // &lt;-- this throws an exception when there is no longer any data left
  
              // It will hit this when it's done; when there are no records left, webResponse's content is "[]" and thus a length of 2
              if ((webResponse.StatusCode != HttpStatusCode.OK) || (webResponse.ContentLength &lt; 3)) {
                  moreRecordsExist = false;
              }
              else // ((webResponse.StatusCode == HttpStatusCode.OK) &amp;&amp; (webResponse.ContentLength &gt; 2))
              {
                  var reader = new StreamReader(webResponse.GetResponseStream());
                  string s = reader.ReadToEnd();
                  var arr = JsonConvert.DeserializeObject&lt;JArray&gt;(s);
  
                  foreach (JObject obj in arr)
                  {
                      string id = (string)obj["Id"];
                      lastIDFetched = id;
                      int packSize = (Int16)obj["PackSize"];
                      string description = (string)obj["Description"];
                      int dept = (Int16)obj["DeptSubdeptNumber"];
                      int subdept = (Int16)obj["InvSubdepartment"];
                      string vendorId = (string)obj["InventoryName"];
                      string vendorItem = (string)obj["VendorItemId"];
                      double avgCost = (Double)obj["Cost"];
                      double unitList = (Double)obj["ListPrice"];
  
                      inventoryItems.Add(new WebAPIClientUtils.InventoryItem
                      {
                          Id = id,
                          InventoryName = vendorId,
                          UPC_PLU = vendorId,
                          VendorItemId = vendorItem,
                          PackSize = packSize,
                          Description = description,
                          Quantity = 0.0,
                          Cost = avgCost,
                          Margin = (unitList - avgCost),
                          ListPrice = unitList,
                          DeptSubdeptNumber = dept,
                          InvSubdepartment = subdept
                      });
                      // Wrap around on reaching 100 with the progress bar; it's thus sort of a hybrid determinate/indeterminate value that is shown
                      if (progressBar1.Value &gt;= 100)
                      {
                          progressBar1.Value = 0;
                      }
                      progressBar1.Value += 1;
                  }
              } // if ((webResponse.StatusCode == HttpStatusCode.OK) &amp;&amp; (webResponse.ContentLength &gt; 0))
          } // while
  
          if (inventoryItems.Count &gt; 0)
          {
              dataGridViewGETResults.DataSource = inventoryItems;
          }
          MessageBox.Show(string.Format("{0} results found", inventoryItems.Count));
      }
      catch (Exception ex)
      {
          // After all records are read, this exception is thrown, so commented out the message; thus, this is really *expected*, and is not an "exception"
          //MessageBox.Show(ex.Message);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>...and the Web API REST Controller code is:</p>
  
  <pre><code>public class InventoryItemsController : ApiController
  {
      static readonly IInventoryItemRepository inventoryItemsRepository = new InventoryItemRepository();
  
      public IEnumerable&lt;InventoryItem&gt; GetBatchOfInventoryItemsByStartingID(string ID, int CountToFetch)
      {
          return inventoryItemsRepository.Get(ID, CountToFetch); 
      }
  
  }
  </code></pre>
  
  <p>...and the (im?)pertinent Repository code is:</p>
  
  <pre><code>public IEnumerable&lt;InventoryItem&gt; Get(string ID, int CountToFetch)
  {
      return inventoryItems.Where(i =&gt; 0 &lt; String.Compare(i.Id, ID)).Take(CountToFetch);
  }
  </code></pre>
  
  <p>One would think I could have a method like this:</p>
  
  <pre><code>public IEnumerable&lt;InventoryItem&gt; Get()
  {
      return inventoryItems.Count();
  }
  </code></pre>
  
  <p>...which would be recognized due to having no args as being different from the other one (even without the routing extravaganza, all attempts at appeasement by me failing ignominiously anyway yesterday).</p>