更新到Microsoft.AspNet.WebApi.OData 5.3.x后无法将数据保存到OData控制器 [英] Can't save the data to OData controller after updating to Microsoft.AspNet.WebApi.OData 5.3.x

查看:81
本文介绍了更新到Microsoft.AspNet.WebApi.OData 5.3.x后无法将数据保存到OData控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定确切更改了哪些内容并导致此部分错误(由于检索数据时未发生此错误),但是在将Microsoft.AspNet.WebApi.OData库更新为5.3.x版本之后,微风将数据保存到OData时出现问题控制器。关于批处理请求的网址。

Not sure what's changed exactly and causing this partial error (since it's not happening with retrieving the data) but after updating Microsoft.AspNet.WebApi.OData library to 5.3.x version, breeze has an issue with saving the data to OData controller. It's about the urls of the batch requests.

它也可以与breeze自己的示例OData项目一起复制;

http://www.breezejs.com/samples/breeze-web-api-odata

It can be reproduced with breeze's its own sample OData project as well;
http://www.breezejs.com/samples/breeze-web-api-odata

如果查看BatchHandler类的 ExecuteRequestMessagesAsync 方法,则项目的 RequestUri 属性包含OData路由前缀两次。

If you look at ExecuteRequestMessagesAsync method of the BatchHandler class, RequestUri property of the items contain OData route prefix two times.

Microsoft.AspNet.WebApi.OData库5.2.2 url

Microsoft.AspNet.WebApi.OData library 5.2.2 url

http://localhost:55802/odata/TodoItems

Microsoft.AspNet.WebApi .OData库5.3.1网址

Microsoft.AspNet.WebApi.OData library 5.3.1 url

http://localhost:55802/odata/odata/TodoItems

任何想法如何解决此问题?

Any ideas how to solve this issue?

微风版本:1.5 .1

breeze version: 1.5.1

推荐答案

噢,欢乐。微软再次更改了其Web API OData的实现...

Oh joy. Microsoft has changed their Web API OData implementation ... again

感谢您挖掘@ coni2k并确定问题所在。

Thanks for digging in, @coni2k, and identifying the problem.

幸运的是,您不必修补Breeze 。我们特意公开 getRoutePrefix 方法,以便您可以在外部进行更改以满足您的需求。

Fortunately, you do NOT have to patch Breeze. We deliberately expose the getRoutePrefix method so you can change it externally yourself to meet your needs.

在以下示例中,我将您的建议合并到该方法的正文中。

In the following example, I've incorporated your suggestion in the body of the method.

var adapter = breeze.config.getAdapterInstance('dataservice', 'webApiOdata');
adapter.getRoutePrefix = getRoutePrefix531; // plug-in alternative for THIS adapter instance.

function getRoutePrefix531(dataService) {
    // Copied from breeze.debug and modified for Web API OData v.5.3.1.
    if (typeof document === 'object') { // browser
      var parser = document.createElement('a');
      parser.href = dataService.serviceName;
    } else { // node
      parser = url.parse(dataService.serviceName);
    }
    // THE CHANGE FOR 5.3.1: Add '/' prefix to pathname
    var prefix = parser.pathname;
    if (prefix[0] !== '/') {
        prefix = '/' + prefix;
    } // add leading '/'  (only in IE)
    if (prefix.substr(-1) !== '/') {
        prefix += '/';
    } // ensure trailing '/'
    return prefix;
  };

在撰写本文时,我们不确定如何检测您正在谈论的Web API OData版本

As I write we're not sure how to detect which version of Web API OData you're talking to which makes it difficult for us to say a priori which version of getRoutePrefix is right for your application.

希望最终能解决这个问题。不要敢将默认值更改为此新版本,因为这会破坏必须与旧版Web API OData进行通信的每个现有应用程序。不确定我们如何赢得这场比赛。我们来看一下。现在令人沮丧。

Hope to figure this out eventually. Don't dare change the default to this new version because that would break every existing app that has to talk to an older version of Web API OData. Not sure how we can win this game. We'll look at it. Frustrating for now.

这篇关于更新到Microsoft.AspNet.WebApi.OData 5.3.x后无法将数据保存到OData控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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