Azure移动服务自定义API在客户端上收到错误的请求 [英] Azure Mobile Services Custom API Getting Bad Request on Client

查看:74
本文介绍了Azure移动服务自定义API在客户端上收到错误的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用azure移动服务后端来尝试制作自定义API.但是,我似乎甚至无法从客户端连接到模板表.当您使用模板制作新的Azure移动服务时,它们会为您提供类似于这种格式的values API控制器

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) }}

{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?

推荐答案

您说的是Mobile Service,但您使用的控制器是MobileAppController.

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

这表明您实际上正在使用移动应用程序.如果您查看服务器项目的packages.config,则可能会看到类似这样的内容.

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" />

我怀疑您得到的400是因为您使用的Mobile Client版本低于2.0.0.

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" />

您还应该检查400响应的正文以获得明确的错误消息.我希望它像这样:

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"}

这篇关于Azure移动服务自定义API在客户端上收到错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆