Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Mobile Services Custom API Getting Bad Request on Client

So I'm using azure mobile services backend to try and make a custom API. However I can't seem to connect to even the template table from the client. When you make a new Azure Mobile Service using the template they provide you with this values API controller that resembles this format

[MobileAppController]
public class ValuesController : ApiController
{
    // GET api/values
    [Route("api/values")]
    public string Get()
    {
        return "test";
    }
}

From the client I'm trying to invoke this endpoint like this

var result = mobileService.InvokeApiAsync<string>("values", HttpMethod.Get, null).Result;

And for some reason I keep getting this exception

{"The request could not be completed. (Bad Request)"}

{Method: GET, RequestUri: 'http://localhost:58457/api/values', Version: 1.1, Content: <null>, Headers: { X-ZUMO-FEATURES: AT X-ZUMO-INSTALLATION-ID: b04f4e19-4f41-46ed-9767-9c1352037559 Accept: application/json User-Agent: ZUMO/1.3 User-Agent: (lang=Managed; os=Windows; os_version=6.1.65536.7601; arch=Win32NT; version=1.3.30324.0) X-ZUMO-VERSION: ZUMO/1.3 (lang=Managed; os=Windows; os_version=6.1.65536.7601; arch=Win32NT; version=1.3.30324.0) }}

This is only the template too, so I need this to work before I get any of my custom endpoints up and running. Any ideas on what the issue may be?

like image 590
Dillon Drobena Avatar asked Feb 13 '16 16:02

Dillon Drobena


2 Answers

You can opt out of version checking by setting a value of true for the app setting MS_SkipVersionCheck. Specify this either in your web.config or in the Application Settings section of the Azure Portal. enter image description herems_skipversioncheck to true in the portal.

like image 174
Rami Sarieddine Avatar answered Sep 30 '22 04:09

Rami Sarieddine


You say Mobile Service, but the controller you're using is MobileAppController.

This indicates you're actually using Mobile App. If you look in your server project packages.config, you may see something like this.

 <package id="Microsoft.Azure.Mobile.Server" version="1.0.119.0" targetFramework="net45" />

I suspect that the 400 you are getting is because you're using a Mobile Client version less than 2.0.0.

In your client project package config, try using a newer client version, such as:

<package id="Microsoft.Azure.Mobile.Client" version="2.0.1" targetFramework="win81" />

You should also inspect the body of the 400 response to get an explicit error message. I expect it to say something like:

{"message":"No API version was specified in the request, this request needs to specify a ZUMO-API-VERSION of '2.0.0'.  For more information and supported clients see: http://go.microsoft.com/fwlink/?LinkId=690568#2.0.0"}
like image 45
Aziel Avatar answered Sep 30 '22 06:09

Aziel