简体   繁体   English

微风| datajs-没有数据处理程序

[英]Breeze | datajs - no handler for data

I am new in breeze world, but I want use it in my application. 我是微风世界中的新手,但是我想在应用程序中使用它。 I tried test it with simple ASP.Net Api OData service based on Northwind.sdf database. 我尝试使用基于Northwind.sdf数据库的简单ASP.Net Api OData服务对其进行测试。

In DataService project I have a simple controller: 在DataService项目中,我有一个简单的控制器:

[BreezeController]
public class CategoriesController : ODataController
{
    readonly EFContextProvider<NORTHWNDContext> contextProvider =
        new EFContextProvider<NORTHWNDContext>();

    [HttpGet]
    [EnableBreezeQuery]
    public IQueryable<Category> GetCategories()
    {
        return contextProvider.Context.Categories;
    }

    [HttpPost]
    public SaveResult SaveChanges(JObject saveBundle)
    {
        return contextProvider.SaveChanges(saveBundle);
    }
}

And on client I call: 在客户我打电话给:

breeze.config.initializeAdapterInstance("dataService", "webApiOData", false);

var manager = new breeze.EntityManager({
    dataService: new breeze.DataService({
        serviceName: "http://localhost:18384/",
        hasServerMetadata: true,
        adapterName: "webApiOData"
    })
});

breeze.EntityQuery.from('Categories').using(manager).execute();

Problem occures in datajs.js file in this method 用这种方法在datajs.js文件中出现问题

var dispatchHandler = function (handlerMethod, requestOrResponse, context) {
    /// <summary>Dispatches an operation to handlers.</summary>
    /// <param name="handlerMethod" type="String">Name of handler method to invoke.</param>
    /// <param name="requestOrResponse" type="Object">request/response argument for delegated call.</param>
    /// <param name="context" type="Object">context argument for delegated call.</param>

    var i, len;
    for (i = 0, len = handlers.length; i < len && !handlers[i][handlerMethod](requestOrResponse, context); i++) {
    }

    if (i === len) {
        throw { message: "no handler for data" };
    }
};

It allways throws "no handler for data" exception but I dont understand. 它总是抛出“没有数据处理程序”异常,但我不明白。 There are already some default odata handlers like 已经有一些默认的odata处理程序,例如

var handlers = [odata.jsonHandler, odata.atomHandler, odata.xmlHandler, odata.textHandler];

Can somebody help me with this problem? 有人可以帮我解决这个问题吗? Thanks. 谢谢。

I think you are missing Metadata in your contoller 我认为您在控制器中缺少元数据

public string Metadata()
    {
        return _contextProvider.Metadata();
    }

If your service uses OData version 4 then DataJs and inherently BreezeJs (which usess datajs) will throw this exception as you have found. 如果您的服务使用的是OData版本4,则DataJ和固有的BreezeJ (使用datajs)将引发此异常。

Breeze has an open issue for this: https://github.com/Breeze/breeze.js/issues/39 . Breeze对此有一个未解决的问题: https : //github.com/Breeze/breeze.js/issues/39 It looks like you can use this BreezeJs adapter to solve problems with OData version 4.0: https://github.com/tschettler/breezejs-odata4-adapter 看来您可以使用此BreezeJs适配器解决OData 4.0版的问题: https : //github.com/tschettler/breezejs-odata4-adapter

Here is a status report as of May 2014 that confirms the above: http://www.odata.org/blog/status-updates-of-odata-libraries-that-support-odata-version-4-0/ 以下是截至2014年5月的状态报告,该报告确认了上述内容: http : //www.odata.org/blog/status-updates-of-odata-libraries-that-support-odata-version-4-0/

For OData version 4 you can use another javascript library called Olingo as described here: http://olingo.apache.org/doc/javascript/index.html 对于OData版本4,您可以使用另一个名为Olingo的JavaScript库,如下所述: http ://olingo.apache.org/doc/javascript/index.html

Here is a summary of libraries with specified supported version: http://www.odata.org/libraries/ 以下是具有指定支持版本的库的摘要: http : //www.odata.org/libraries/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM