I have created a backend service using Azure Mobile App. Offline sync works fine with mobile clients using provided SDK. All the controllers that I have used are TableController. Now I want to add a simple Web API 2 controller ApiController, that will not be used by mobile clients.
Here is a simple ApiController that I have added to Controllers folder:
public class SimpleController : ApiController
{
public string Get()
{
return "Hello";
}
}
But the controller is never hit. If I add [MobileAppController] attrebute to the controller, it works but now it asks for additional headers in the request (I guess this headers are sent by client SDK):
{"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"}
But I do not need this additional functionality here - I just want my service to respond to simple GET requests. Although the guide states that it is not necessary to decorate the class:
Any controller that does not have
MobileAppControllerAttributeapplied can still be accessed by clients, but it may not be correctly consumed by clients using any Mobile App client SDK.
I can not achieve this. Am I missing something?
Thanks
I have figured out how to use both types of controllers.
Just add a call to config.MapHttpAttributeRoutes(); in your StartUp.ConfigureMobileApp method like this:
public static void ConfigureMobileApp(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
//For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686
config.EnableSystemDiagnosticsTracing();
config.MapHttpAttributeRoutes(); //Add this line
new MobileAppConfiguration()
.UseDefaultConfiguration()
.ApplyTo(config);
... //rest of the code
}
And then decorate your controller with custom route:
[Route("api/Simple")] //add this
public class SimpleController : ApiController
{
public string Get()
{
return "Hello";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With