Current filter:
                                You should refresh the page.
                                  • Description:
                                    I am trying to create a DXTREME based HTML5/JS application for a mobile platform that will retrieve data from the legacy OData service. I am using the ODataContext class to work with ODataService, but all requests to ODataServices return an error. Have I missed something important?

                                    This approach is intended for users who are creating an OData service manually. If you create an OData service using our DevExtreme WCF OData Service project template, you do not need to follow recommendations from this article, because all the necessary modifications will be added automatically.

                                    We provide a class intended to help you retrieve data from the OData service and perform CRUD operations: ODataContext.
                                    As a mobile browser application is usually hosted on a different domain than the OData service, there are some requirements the OData service must meet. The requirements that the ODataContext apply to the OData service are:

                                    1. The OData service must support the JSONP data format.
                                    2. The OData service must support the cross domain POST, MERGE, and DELETE operations.
                                    1. Enabling JSONP support.
                                    To enable JSONP support, please use the solution provided in the JSONP and URL-controlled format support for ADO.NET Data Services article.
                                    All that you need is to download the assembly available in the "Download" section and add a reference to this assembly to the OData service project. Then, simply apply the JSONPSupportBehaviorAttribute attribute to the service class.
                                    To make the JSONPSupportBehavior module work for WCF Data Services 5.0, it is necessary to slightly modify its source code. The solution is provided in the discussion of this article: JSONP and URL-controlled format support for ADO.NET Data Services. All you need to change is one line in the JSONPSupportInspector.AfterReceiveRequest method. Replace this line
                                    httpmsg.Headers["Accept"] = "application/json, text/plain;q=0.5";

                                    with the following one:

                                    httpmsg.Headers["Accept"] = "application/json, text/plain;q=0.5,application/json;odata=verbose";

                                    By the way, you can vote for adding the JSONP format support into the standard WCF Data Service implementation: add $format=json support in query URL.
                                    2. Enabling cross domain operations support.
                                    To allow clients to send cross domain requests, handle the HttpApplication.BeginRequest event. In this event handler, check whether or not the HttpRequest headers contain an Origin header. If the origin is specified, add the Access-Control-Allow-Origin and Access-Control-Allow-Credentials headers to the response. In addition, copy the Access-Control-Request-Method and Access-Control-Request-Headers request headers' values to the Access-Control-Allow-Methods and Access-Control-Allow-Headers response headers, respectively. If the HttpMethod is "OPTIONS", set the HttpResponce.StatusCode value to 204.
                                    Here are steps to implement this:
                                    a. Add the Global.asax file to the OData service project if it is not yet added.
                                    b. Add the following method to the Global.asax file:

                                    /// <summary> /// Enables cross domain POST, MERGE, DELETE for Firefox and Chrome /// This requires: /// <system.ServiceModel> /// <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> /// </summary> static void EnableCrossDomain() { string origin = HttpContext.Current.Request.Headers["Origin"]; if (string.IsNullOrEmpty(origin)) return; HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", origin); string method = HttpContext.Current.Request.Headers["Access-Control-Request-Method"]; if (!string.IsNullOrEmpty(method)) HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", method); string headers = HttpContext.Current.Request.Headers["Access-Control-Request-Headers"]; if (!string.IsNullOrEmpty(headers)) HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", headers); HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true"); if (HttpContext.Current.Request.HttpMethod == "OPTIONS") { HttpContext.Current.Response.StatusCode = 204; HttpContext.Current.Response.End(); } }
                                    ''' <summary> ''' Enables cross domain POST, MERGE, DELETE for Firefox and Chrome ''' This requires: ''' <system.ServiceModel> ''' <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> ''' </summary> Shared Sub EnableCrossDomain() Dim origin As String = HttpContext.Current.Request.Headers("Origin") If String.IsNullOrEmpty(origin) Then Return End If HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", origin) Dim method As String = HttpContext.Current.Request.Headers("Access-Control-Request-Method") If (Not String.IsNullOrEmpty(method)) Then HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", method) End If Dim headers As String = HttpContext.Current.Request.Headers("Access-Control-Request-Headers") If (Not String.IsNullOrEmpty(headers)) Then HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", headers) End If HttpContext.Current.Response.AddHeader("Access-Control-Allow-Credentials", "true") If HttpContext.Current.Request.HttpMethod = "OPTIONS" Then HttpContext.Current.Response.StatusCode = 204 HttpContext.Current.Response.End() End If End Sub

                                    Execute this method in the Application_BeginRequest event handler:

                                    protected void Application_BeginRequest(object sender, EventArgs e) { EnableCrossDomain(); }
                                    Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) EnableCrossDomain() End Sub

                                    Finally, open the Web.config file and add this code into the <configuration> section:

                                    <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> </system.serviceModel>

                                    See also:

                                    Creating the Data Service

                                0 Solutions

                                Creation Date Importance Sort by