Azure移动服务Custom API GET不返回XML而不是Json

时间:2016-02-05 16:05:18

标签: azure azure-mobile-services

最近开始研究Azure移动服务并喜欢它。我通常更喜欢使用ASP.NET Web API,但对于移动解决方案或任何快速REST API开发都喜欢这种方法。当我从我的Web API代码添加控制器/自定义API到移动项目时,试图找出自定义API。它的工作非常好并且简化了但是当我看到响应时它比其他ToDo项目API提供XML而不是Json响应。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Microsoft.WindowsAzure.Mobile.Service;
using System.Threading.Tasks;
using ProjectService.Models;
using Newtonsoft.Json;

namespace ProjectService.Controllers
{
    public class ProjectController : ApiController
    {
        public ApiServices Services { get; set; }

        // GET api/Search
        public async Task<Movie> Get(string term)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

            var baseAddress = new Uri("http://api.themoviedb.org/3/");

            using (var httpClient = new HttpClient { BaseAddress = baseAddress })
            {
                httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json");

                using (var response = await httpClient.GetAsync("search/movie?api_key=KEY-ID&query=" + term))

                {
                    string responseData = await response.Content.ReadAsStringAsync();

                    var model = JsonConvert.DeserializeObject<Movie>(responseData);

                    return model;

                    //I Tried with return Json AllowGet it's returning XML
                    //return Json(model, JsonRequestBehavior.AllowGet);

                }
            }
        }
    }
}

0 个答案:

没有答案