title: How to consume WCF Data Service WebGet method in MVC?
body: <p>Lets say I have a WebGet method:  </p>
  
  <pre><code>[WebGet]
  public IQueryable&lt;State&gt; GetStatesStartingWithLetter(string letter)
  {
       return CurrentDataSource.States.Where(s =&gt; s.Name.Substring(0, 1).Equals(letter.Substring(0, 1),
              StringComparison.InvariantCultureIgnoreCase)).OrderBy(s =&gt; s.Name);
  }
  </code></pre>
  
  <p>I can consume it in a browser like so:  </p>
  
  <pre><code>http://localhost:55576/WcfDataService.svc/GetStatesStartingWithLetter?letter='a'
  </code></pre>
  
  <p>However, what do I have to do in an MVC3 controller to call the method? I have added the service reference and I can use the context without a problem. The code below spits a list of states out to the screen at the /Controller/States URL.</p>
  
  <pre><code>public ActionResult States()
  {
      MyDbContext ctx = new MyDbContext(new Uri("http://localhost:55576/WcfDataService.svc/"));
  
      var temp = from state in ctx.States
                 select state;
  
      return View(temp);
  }
  </code></pre>
  
  <p>I don't see any EASY way to just call the WebGet method though, its not exposed on the service as I would expect it to be. Am I missing something? I can get the results by doing this:</p>
  
  <pre><code>public ActionResult States()
  {
      WhelenDbContext ctx = new WhelenDbContext(new Uri("http://localhost:55576/WcfDataService.svc/"));
  
      var temp = ctx.Execute&lt;State&gt;(new Uri("http://localhost:55576/WcfDataService.svc/GetStatesStartingWithLetter?letter='a'"));
  
      return View(temp);
  }
  </code></pre>
  
  <p>..but that seems a bit ridiculous. Any suggestions are much appreciated.</p>