我正在構建一個SAPUI5的Web應用程序,它提供了一系列服務,這些服務存儲在MongoDB中,並可作爲OData使用。 我遵循這個指南jaydata-install-your-own-odata-server-with-nodejs-and-mongodb,這些都是我的model.js:OData Jaydata - odata更新請求返回錯誤404(SAPUI5,節點)
$data.Class.define("marketplace.Service", $data.Entity, null, {
Id: {type: "id", key: true, computed: true, nullable: false},
Name: {type: "string", nullable: false, maxLength: 50},
}, null);
$data.Class.defineEx("marketplace.Context", [$data.EntityContext, $data.ServiceBase], null, {
Services: {type: $data.EntitySet, elementType: marketplace.Service}
});
exports = marketplace.Context;
和server.js:
var c = require('express');
require('jaydata');
window.DOMParser = require('xmldom').DOMParser;
require('q');
require('./model.js');
var app = c();
app.use(c.query());
app.use(c.bodyParser());
app.use(c.cookieParser());
app.use(c.methodOverride());
app.configure(function() {app.use(app.router);});
app.use(c.session({secret: 'session key'}));
app.use("/marketplace", $data.JayService.OData.Utils.simpleBodyReader());
app.use("/marketplace", $data.JayService.createAdapter(marketplace.Context, function (req, res) {
return new marketplace.Context({
name: "mongoDB",
databaseName: "marketplace",
address: "localhost",
port: 27017
});
}));
app.use("/", c.static(__dirname));
app.use(c.errorHandler());
app.listen(8080);
客戶端通過使用SAPUI5開發,這些都是相對於代碼的部分odata模型創建:
oModel = sap.ui.model.odata.ODataModel("http://localhost:8080/marketplace", false); // connection to the odata endpoint
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
sap.ui.getCore().setModel(oModel);
各種服務正確顯示在一個SAPUI5表中,我很容易能夠插入一個新的服務,通過使用POST OData.request以這種方式:
OData.request({
requestUri: "http://localhost:8080/marketplace/Services",
method: "POST",
data: newEntry // json object with the new entry
},
function(insertedItem) {
// success notifier
},
function(err) {
// error notifier
}
);
並且通過以這種方式使用的SAPUI5函數oModel.remove()刪除服務(oParams是JSON對象包含警報通知功能):
var serviceId = oTable.getRows()[selectedIndex].getCells()[0].getText();
oModel.remove("/Services('" + serviceId + "')", oParams);
一切正常,但單個服務的更新請求。我已經嘗試過使用SAPUI5(oModel.update或oModel.submitChanges)提供的函數,通過使用OData.request(「method:PUT」),通過創建一個ajax PUT請求,我也嘗試使用Fiddler創建PUT請求。 我總是得到錯誤404:
Request URL:http://localhost:8080/marketplace/Services('NTMzZDM3M2JlNjY2YjY3ODIwZjlmOTQ0')
Request Method:PUT
Status Code:404 Not Found
哪裏是什麼問題?我試過Chrome,IE和Firefox;同樣的問題... 感謝
當通網址的http://本地主機:8080 /市場/服務(「NTMzZDM3M2JlNjY2YjY3ODIwZjlmOTQ0」)與GET方法,它是否返回正確的條目? – Maya
是的!當使用具有相同URI的GET方法時,我正確地獲取條目的XML/ATOM! – Marco