Sencha touch 我是否可以将ASP.NET MVC3专门用作RESTful Web服务?

Sencha touch 我是否可以将ASP.NET MVC3专门用作RESTful Web服务?,sencha-touch,web-services,asp.net-mvc-3,Sencha Touch,Web Services,Asp.net Mvc 3,我正在为我们当地的教堂建立一个只读应用程序 我们使用Vimeo来主持我们所有的视频,我想将Vimeo视频和RSS提要集成到我们的web应用程序中 应用程序中其余的“内容”将是静态的“信息”以及联系方式 我的问题是,仅使用ASP.NET MVC3(减去“V”)将JSON驱动到我们的web应用程序是否符合犹太教原则?是的,这非常有效。只需返回一个JsonResult 以下是我在生产中使用的一个示例: public partial class StudentController : BaseCont

我正在为我们当地的教堂建立一个只读应用程序

我们使用Vimeo来主持我们所有的视频,我想将Vimeo视频和RSS提要集成到我们的web应用程序中

应用程序中其余的“内容”将是静态的“信息”以及联系方式


我的问题是,仅使用ASP.NET MVC3(减去“V”)将JSON驱动到我们的web应用程序是否符合犹太教原则?

是的,这非常有效。只需返回一个JsonResult

以下是我在生产中使用的一个示例:

 public partial class StudentController : BaseController {
    public StudentController(RESTContext portalContext)
        : base(portalContext) { }

    [HttpGet, Url("organizations/{organizationId?}/students")]
    public virtual JsonResult List(Guid? organizationId) {
        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotAuthorizedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted);

        return Json(cases, JsonRequestBehavior.AllowGet);
    }

    [HttpGet, Url("organizations/{organizationId?}/students/{studentId?}")]
    public virtual JsonResult Get(Guid? organizationId, Guid? studentId) {
        if (studentId.IsNull())
            throw new HttpNotFoundExecption();

        if (organizationId != RESTContext.OrganizationId)
            throw new HttpNotModifiedException();

        var query = RESTContext.GetQuery<IQuery<StudentCasesReport>>()
            .Where(x => x.OrganizationId, organizationId)
            .Where(x => x.StudentCaseId, studentId)
            .OrderBy(x => x.LastName, SortOrder.Ascending);
        var cases = query.Execute(IsolationLevel.ReadUncommitted).FirstOrDefault();

        if (cases.IsNull())
            throw new HttpNotFoundExecption();

        return Json(cases, JsonRequestBehavior.AllowGet);
    }
}
公共部分类StudentController:BaseController{
公共学生控制器(RESTContext portalContext)
:base(portalContext){}
[HttpGet,Url(“organizations/{organizationId?}/students”)]
公共虚拟JsonResult列表(Guid?组织ID){
if(organizationId!=RESTContext.organizationId)
抛出新的HttpNotAuthorizedException();
var query=RESTContext.GetQuery()
.Where(x=>x.OrganizationId,OrganizationId)
.OrderBy(x=>x.LastName,SortOrder.升序);
var cases=query.Execute(IsolationLevel.ReadUncommitted);
返回Json(cases,JsonRequestBehavior.AllowGet);
}
[HttpGet,Url(“organizations/{organizationId?}/students/{studentId?}”)]
公共虚拟JsonResult Get(Guid?组织ID,Guid?学生ID){
if(studentId.IsNull())
抛出新的HttpNotFoundExection();
if(organizationId!=RESTContext.organizationId)
抛出新的HttpNotModifiedException();
var query=RESTContext.GetQuery()
.Where(x=>x.OrganizationId,OrganizationId)
.Where(x=>x.StudentCaseId,studentId)
.OrderBy(x=>x.LastName,SortOrder.升序);
var cases=query.Execute(IsolationLevel.ReadUncommitted).FirstOrDefault();
if(cases.IsNull())
抛出新的HttpNotFoundExection();
返回Json(cases,JsonRequestBehavior.AllowGet);
}
}

这正是我所想的。我是web服务新手,所以我有点担心最佳实践。您还需要处理404和其他状态代码。MVC3现在为您提供了向用户返回状态代码的选项。我建议使用AttributeRouteMapper项目在控制器级别作为属性控制路由。使其更易于维护+1在这个问题上-绝对。有人说GoWCF——但我这里的第一选择始终是mvc,特别是因为您已经有了一个web应用程序,REST web服务代码看起来非常相似。您可以更进一步,定义一个自定义操作调用程序,以便返回模型实例而不是JSON结果。调用程序可以检查Accept头或querystring以确定如何序列化模型。