微风| datajs-没有数据处理程序 [英] Breeze | datajs - no handler for data

查看:123
本文介绍了微风| datajs-没有数据处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是微风世界中的新手,但是我想在我的应用程序中使用它.我尝试使用基于Northwind.sdf数据库的简单ASP.Net Api OData服务对其进行测试.

在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);
    }
}

然后我打电话给客户:

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();

此方法在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" };
    }
};

它总是抛出没有数据处理程序"异常,但我不明白.已经有一些默认的odata处理程序,例如

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

有人可以帮助我解决这个问题吗?谢谢.

解决方案

如果您的服务使用OData版本4,则 DataJs 和本质上 BreezeJs (使用datajs)会在您发现时抛出此异常.

Breeze对此有一个未解决的问题: https://github.com/Breeze /breeze.js/issues/39 .看来您可以使用此BreezeJs适配器解决OData 4.0版的问题: https://github .com/tschettler/breezejs-odata4-adapter

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

对于OData版本4,您可以按以下说明使用另一个名为Olingo的JavaScript库: http ://olingo.apache.org/doc/javascript/index.html

以下是具有指定受支持版本的库的摘要: http://www.odata.org/libraries /

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.

In DataService project I have a simple controller:

[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

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

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

Can somebody help me with this problem? Thanks.

解决方案

If your service uses OData version 4 then DataJs and inherently BreezeJs (which usess datajs) will throw this exception as you have found.

Breeze has an open issue for this: 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

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/

For OData version 4 you can use another javascript library called Olingo as described here: http://olingo.apache.org/doc/javascript/index.html

Here is a summary of libraries with specified supported version: http://www.odata.org/libraries/

这篇关于微风| datajs-没有数据处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆