servicestack,Asp.net Mvc 3,servicestack" /> servicestack,Asp.net Mvc 3,servicestack" />

Asp.net mvc 3 ServiceStack MVC自动注册路由

Asp.net mvc 3 ServiceStack MVC自动注册路由,asp.net-mvc-3,servicestack,Asp.net Mvc 3,servicestack,我似乎无法使我的服务自动路由,元数据显示了所有可用的类和服务,但是如果我转到/api/btbcustomervents,我会得到未处理的路由错误 我试过这个: [Alias("btbCustomerEvents")] [RestService("/btbCustomerEvents")] public class Btbcustomerevent : BaseModel 我的AppHost如下所示: public class AppHost: AppHostBase {

我似乎无法使我的服务自动路由,元数据显示了所有可用的类和服务,但是如果我转到/api/btbcustomervents,我会得到未处理的路由错误

我试过这个:

[Alias("btbCustomerEvents")]
[RestService("/btbCustomerEvents")]
public class Btbcustomerevent : BaseModel
我的AppHost如下所示:

public class AppHost: AppHostBase
{       
    public AppHost() : base("Energy System API", typeof(DepartmentService).Assembly) { }

    public override void Configure(Funq.Container container)
    {
        //Set JSON web services to return idiomatic JSON camelCase properties
        ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

        //register all routes
        Routes
            .Add<Department>("/Departments")
            .Add<Department>("/Departments/{Id}")
            .Add<Paymentmethod>("/PaymentMethods")
            .Add<Paymentmethod>("/PaymentMethods/{Id}")
            .Add<MyExampleModel>("/MyExampleModel")
            .Add<MyExampleModel>("/MyExampleModel/{Id}");

        //Change the default ServiceStack configuration
        SetConfig(new EndpointHostConfig{ DebugMode = true, });

        container.Register<ICacheClient>(new MemoryCacheClient());
        container.Register<ISessionFactory>(c => 
            new SessionFactory(c.Resolve<ICacheClient>()));

        ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
    }

    public static void Start()
    {
        new AppHost().Init();
    }
公共类AppHost:AppHostBase
{       
public AppHost():base(“能源系统API”,typeof(DepartmentService).Assembly{}
公共覆盖无效配置(Funq.Container)
{
//设置JSON web服务以返回惯用JSON用例属性
ServiceStack.Text.JsConfig.casenames=true;
//登记所有路线
路线
.Add(“/部门”)
.Add(“/Departments/{Id}”)
.Add(“/PaymentMethods”)
.Add(“/PaymentMethods/{Id}”)
.Add(“/MyExampleModel”)
.Add(“/MyExampleModel/{Id}”);
//更改默认ServiceStack配置
SetConfig(newendpointhostconfig{DebugMode=true,});
Register(newmemorycacheclient());
容器。寄存器(c=>
新SessionFactory(c.Resolve());
ControllerBuilder.Current.SetControllerFactory(新的FunqControllerFactory(container));
}
公共静态void Start()
{
新建AppHost().Init();
}
我真的不想添加所有的路由,我已经创建了TT文件,从数据库中创建了模型,还自动添加了rest服务/CRUD样式,现在我不得不手动添加每个路由,这看起来很遗憾

有人有解决办法吗


谢谢

是的,路由的自动注册已经内置到ServiceStack中。使用
routes.AddFromAssembly()
扩展方法,它将为指定程序集中的所有服务注册自定义路由(对于您有实现的所有谓词),例如:


有关如何在具有不同启发式的情况下自动注册自己的路由的模板,请参阅。

您好,谢谢我收到错误:异常详细信息:System.Reflection.AmbiguousMatchException:属性名称不区分大小写:DbaIndexdefraglog.ErrorMessage但大小写和拼写正确?您也尝试过服务,但获得了same错误消息。我在创建其他路由之前将代码放在AppHost/Configure中,如果这样做了,您能否更具体一点,谢谢这是手动注册路由的替代方法。例如,删除任何看起来像
/{RequestDto}
/{RequestDto}/{Id}的路由
因为上面的代码行已经对指定程序集中的每项服务执行了此操作。您好,谢谢,是的,我这样做了,它掉下来了,不喜欢一些表,我只能升级代码,到目前为止还不能升级数据库,我注意到的一件事是base(“Energy System API”,typeof(DepartmentService)。不应该指向该服务,因此我更正了此问题并修改了我的TT文件以自动添加RestService链接,谢谢您的帮助
//    /{RequestDto}
//    /{RequestDto}/{Id} - if Id exists
Routes.AddFromAssembly(typeof(Department).Assembly);