title: Trouble calling a ASP.NET MVC 4 WebApi from a Windows Store Application
body: <p>I've got the following code running in a Windows Store application that is <em>supposed</em> to call one of my WebApis:</p>
  
  <pre><code>using (var client = new HttpClient())
  {
      var parms = new Dictionary&lt;string, string&gt;
          {
              {"vinNumber", vinNumber}, 
              {"pictureType", pictureType}, 
              {"blobUri", blobUri}
          };
  
      HttpResponseMessage response;
  
      using (HttpContent content = new FormUrlEncodedContent(parms))
      {
          const string url = "http://URL/api/vinbloburis";
  
          response = await client.PostAsync(url, content);
      }
  
      return response.StatusCode.ToString();
  }
  </code></pre>
  
  <p>The WebApi code looks like this:</p>
  
  <pre><code>[HttpPost]
  public HttpResponseMessage Post(string vinNumber, string pictureType, string blobUri)
  {
      var vinEntity = new VinEntity
          {
              PartitionKey = vinNumber,
              RowKey = pictureType, 
              BlobUri = blobUri
          };
  
      _vinRepository.InsertOrUpdate(vinEntity);
  
      return new HttpResponseMessage { Content = new StringContent("Success"), StatusCode = HttpStatusCode.OK };
  }
  </code></pre>
  
  <p>Using Fiddler, I've observed the following ... here's what the request looks like:</p>
  
  <pre><code>POST http://URL/api/vinbloburis HTTP/1.1
  Content-Type: application/x-www-form-urlencoded
  Host: URL
  Content-Length: 113
  Expect: 100-continue
  
  vinNumber=vinNumber&amp;pictureType=top&amp;blobUri=https%3A%2F%2Fmystorage.blob.core.windows.net%2Fimages%2Fimage.png
  </code></pre>
  
  <p>But the response is an error with little/no information:</p>
  
  <pre><code>{"Message":"An error has occurred."}
  </code></pre>
  
  <p>I've even tried locally with the debugger attached to the WebApis and my Post method never catches.</p>
  
  <p>Does anyone see something I've missed here? I feel like I'm looking right at it but not seeing it. I should add that I am able to call an HttpGet method while passing a parameter through the querystring. Right now the problem is only with this HttpPost.</p>
  
  <p>Thanks!</p>
  
  <p>UPDATE: Based on some good comments from folks I'm adding some more details.</p>
  
  <p>I have the default routes configured for WebApis ...</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      config.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/{controller}/{id}",
          defaults: new { id = RouteParameter.Optional }
      );
  }
  </code></pre>
  
  <p>Consequently, I think /URL/api/vinbloburis should work. Additionally, as alluded above, I currently have this working with an HttpGet. Here's what's working in the Windows Store app to call the HttpGet WebApi ...</p>
  
  <pre><code>using (var client = new HttpClient())
  {
      using (var response = await client.GetAsync(uri))
      {
          if (response.IsSuccessStatusCode)
          {
              var sasUrl = await response.Content.ReadAsStringAsync();
              sasUrl = sasUrl.Trim('"');
  
              return sasUrl;
          }
      }
  }
  </code></pre>
  
  <p>... and it's calling the following WebApi ...</p>
  
  <pre><code>[HttpGet]
  public HttpResponseMessage Get(string blobName)
  {
      const string containerName = "images";
      const string containerPolicyName = "policyname";
  
      _helper.SetContainerPolicy(containerName, containerPolicyName);
  
      string sas = _helper.GenerateSharedAccessSignature(blobName, containerName, containerPolicyName);
  
      return new HttpResponseMessage
          {
              Content = new StringContent(sas),
              StatusCode = HttpStatusCode.OK
          };
  }
  </code></pre>
  
  <p>I hope the additional information helps!</p>