3

I am using the John Papa Single Page Application source code to create my own App and I am running into some problems when using the Breeze Web API. I have my own breeze controller and as soon as I add a second HttpGET method I get the error "Multiple actions were found that match the request".

It is Weird because in his code he adds multiple GETs and his code works but I think I am missing something.

Breeze Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Breeze.WebApi;
using AgencyUpdate.Models;

namespace AgencyUpdate.Controllers
{
    [BreezeController]
    public class BreezeController : ApiController
    {

        readonly EFContextProvider<AgencyDbContext> _ContextProvider =
            new EFContextProvider<AgencyDbContext>();

        public string MetaData()
        {
            return _ContextProvider.Metadata();
        }

        [HttpGet]
        public IQueryable<api_Agency> GetAgency()
        {
            return _ContextProvider.Context.api_Agency;
        }


        [HttpGet]
        public IQueryable<api_AgencyOffice> GetOffice()
        {
            return _ContextProvider.Context.api_AgencyOffice;
        }

    }
}

I use this URL to request data:

**http://localhost:13762/api/breeze/GetAgency**

Also I have found this .CS file for routing but I don't know if I have to make changes to it.

BreezeWebApiConfig

using System.Web.Http;

[assembly: WebActivator.PreApplicationStartMethod(
    typeof(AgencyUpdate.App_Start.BreezeWebApiConfig), "RegisterBreezePreStart")]
namespace AgencyUpdate.App_Start {
  ///<summary>
  /// Inserts the Breeze Web API controller route at the front of all Web API routes
  ///</summary>
  ///<remarks>
  /// This class is discovered and run during startup; see
  /// http://blogs.msdn.com/b/davidebb/archive/2010/10/11/light-up-your-nupacks-with-startup-code-and-webactivator.aspx
  ///</remarks>
  public static class BreezeWebApiConfig {

    public static void RegisterBreezePreStart() {
      GlobalConfiguration.Configuration.Routes.MapHttpRoute(
          name: "BreezeApi",
          routeTemplate: "breeze/{controller}/{action}"
      );
    }
  }
}

Does anyone know what the problem is?

4

2 回答 2

2

我觉得我需要使用的 URL 是微风/微风/MethodName 有点愚蠢。

John 的代码没有在 URL 中使用两次微风,因此造成了混乱

于 2013-07-29T10:15:06.983 回答
1

Papa 的课程有单页应用程序跳转启动.zip 文件,其中包含按章节的项目源代码。BreezeWebApiConfig.cs 内容的正确版本如下:

public static class BreezeWebApiConfig {

    public static void RegisterBreezePreStart() {
      GlobalConfiguration.Configuration.Routes.MapHttpRoute(
          name: "BreezeApi",
          routeTemplate: "api/{controller}/{action}"
      );
    }
  }
}

注意字符串routeTemplate: "api/{controller}/{action}"

于 2014-04-24T16:38:56.910 回答