on 12-31-2014 4:13 PM
Hi, SCN.
I noticed in the OpenUI5 JsDoc Report that some headers are not modifiable by mHeaders when specifying a new sap.ui.model.odata.ODataModel object. These headers are: accept, accept-language, x-csrf-token, MaxDataServiceVersion, DataServiceVersion. Is it possible to adjust the Accept header when binding to my service URL?
Let's say I need to also interface with an ASP.NET WebAPI OData Service (using v1-3 OData packages). I can set my Accept header to "application/json;odata=verbose" in order to return results in a verbose JSON format that OData v2 supports. By default, my OData v3 service will return a "JSON light" response, which causes an endless loop of GET requests to my service from the UI5 library.
Thanks,
Mitch
As an alternative, I can set my custom service to properly return JSON response based on MaxDataServiceVersion. This should be handled out-of-the-box from a v1-3 OData package, but unfortunately ASP.NET Web API OData does not support OData v2. I can handle this with a custom message handler, but that is out of scope for this request, and I already have a solution there. I would rather find a way to set Accept header from my client for the time being.
Hi, Barry.
I'm facing the same situation where I'm trying to integrate a .Net Odata service and running into endless loop. What was your alternative to overcome this.
Appreciate your help.
Thanks,
Srini.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am creating my OData model using sap.ui.model.odata.v2.ODataModel
var oAppModel = new ODataModel(
sServiceUrl,
{
json: true,
defaultCountMode: sap.ui.model.odata.CountMode.None,
useBatch: false
}
);
this.setModel(oAppModel);
Then on my ASP.NET OData service, I do have a new Message Handler added in my WebApiConfig.
See this GitHub Gist for the handler I'm using: Verbose JSON for v2 from Web API v1-3 OData · GitHub
You can attach this custom handler in your WebApiConfig like:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// ...
// Check MaxDataServiceVersion and reply with proper JSON response (also validates $format)
config.MessageHandlers.Add(new FormatSupportHandler());
// ...
}
}
Good luck,
Mitch
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.