C# Breeze WebAPI-找到多个与请求匹配的操作
我正在使用John Papa单页应用程序源代码创建自己的应用程序,在使用Breeze Web API时遇到了一些问题。我有自己的breeze控制器,当我添加第二个HttpGET方法时,我会得到错误“发现多个操作与请求匹配” 这很奇怪,因为在他的代码中,他添加了多个get,他的代码运行正常,但我认为我遗漏了一些东西 微风控制器C# Breeze WebAPI-找到多个与请求匹配的操作,c#,api,breeze,C#,Api,Breeze,我正在使用John Papa单页应用程序源代码创建自己的应用程序,在使用Breeze Web API时遇到了一些问题。我有自己的breeze控制器,当我添加第二个HttpGET方法时,我会得到错误“发现多个操作与请求匹配” 这很奇怪,因为在他的代码中,他添加了多个get,他的代码运行正常,但我认为我遗漏了一些东西 微风控制器 using System; using System.Collections.Generic; using System.Linq; using System.Net; u
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;
}
}
}
我还找到了这个用于路由的.CS文件,但我不知道是否必须对其进行更改
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}"
);
}
}
}
使用System.Web.Http;
[组件:WebActivator.PreApplicationStartMethod(
类型(AgencyUpdate.App_Start.BreezeWebApiConfig),“RegisterBreezePreStart”)]
名称空间AgencyUpdate.App\u开始{
///
///在所有Web API路由的前面插入Breeze Web API控制器路由
///
///
///此类在启动期间被发现并运行;请参阅
/// http://blogs.msdn.com/b/davidebb/archive/2010/10/11/light-up-your-nupacks-with-startup-code-and-webactivator.aspx
///
公共静态类BreezeWebApiConfig{
公共静态无效寄存器breezeprestart(){
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
名称:“BreezeApi”,
routeTemplate:“breeze/{controller}/{action}”
);
}
}
}
有人知道问题出在哪里吗?我觉得有点傻,我需要使用的URL是breeze/breeze/MethodName
John的代码在URL中没有两次使用breeze,因此混淆Papa的课程有一个单页的-apps-jumpstart.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}”,您也不必这样做。这一切都取决于你如何设置你的路线我想问题在于Nuget软件包如何为你设置BreezeWebApiConfig文件。在Pluralsight视频中,John使用nick使用的URL(带API)。下面是它自动为您生成的代码:
publicstaticvoidregisterbreezeprestart(){GlobalConfiguration.Configuration.Routes.maphttroute(名称:“BreezeApi”,routeTemplate:“breeze/{controller}/{action}”);
public static class BreezeWebApiConfig {
public static void RegisterBreezePreStart() {
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "BreezeApi",
routeTemplate: "api/{controller}/{action}"
);
}
}
}