w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Configure webAPI oData name for odata.count
OData protocol defines a standard representation for OData requests and responses in JSON format. The metadata key names like odata.count are defined by the spec and are not configurable to improv inter-operability with standard clients. In short, you cannot customize those names.

Categories : Json

WebApi and OData
I feel your pain. The first time i was really forced to change my way of thinking is when I started developing on Ruby On Rails. regarding exposing methods in general, Try doing it in this order: start by exposing the full set of CRUD operations for the resource (aka make your RESTful resource) go back and privatize the things that should not be exposed by doing pre- and post- hooks on those methods for authentication / permissions checks and whatnot. Then, when you've got your resources, a generally good rule of thumb is to show what is necessary before the ? and hide the complexity behind the ?, thus making your resources able to do filtering, but not requiring it. In other words, decorate your methods with filtering. So, lets say you want to have an /orders endpoint: Base URL: /o

Categories : Rest

ASP.NET WebApi OData support for DTOs
Something like this (I haven't tried to compile it) using(var dataContext = new ORM_Context()) { var projects = dataContext.Projects; // IQueryable<Project> //Create a set of ODataQueryOptions for the internal class ODataModelBuilder modelBuilder = new ODataConventionModelBuilder(); modelBuilder.EntitySet<Project>("Project"); var context = new ODataQueryContext( modelBuilder.GetEdmModel(), typeof(Project)); var newOptions = new ODataQueryOptions<Project>(context, Request); var t = new ODataValidationSettings() { MaxTop = 25 }; var s = new ODataQuerySettings() { PageSize = 25 }; newOptions.Validate(t); IEnumerable<Project> internalResults = (IEnumerable<Project>)newOptions.ApplyTo(projects, s); i

Categories : C#

WebAPI ODATA without Entity Framework
Got it. You pointed me into the right direction with your LINQ provider. I found out I can do it easily with the ORM we are using (OpenAccess). More info here :http://docs.telerik.com/data-access/developers-guide/using-web-services/asp.net-web-api/developer-guide-wcfservices-web-api-expose-oacontext

Categories : Asp Net Web Api

Using OData in webapi for properties known only at runtime
There are extension points on how the serialization is done in Web API Odata Here is an example. customizing odata output from asp.net web api Though the question was different, I guess what you want could be done using the same approach (i.e. overriding how the entries are serialized.) Especially, in the overridden CreateEntry you may change entry.Properties (Note that this version is not released yet AFAIK but could be downloaded as a prerelease version.)

Categories : C#

.Net WebApi OData Actions that return an Queryable
Looks like your action configuration is incorrect. Try the following and see if it works: //getLocations.Returns<IQueryable<Location>>(); getLocations.ReturnsCollectionFromEntitySet<Location>("Locations");

Categories : C#

WebAPI OData and customizing navigation links
You could do something like the following: var entities1 = builder.EntitySet<Entity1>("Entities1"); entities1.HasNavigationPropertyLink(entities1.EntityType.NavigationProperties.First(np => np.Name == "OtherEntity"), (context, navigation) => { return new Uri(context.Url.ODataLink(new EntitySetPathSegment("Entities2"), new KeyValuePathSegment(context.EntityInstance.OtherEntity.Id.ToString()))); }, followsConventions: false);

Categories : Asp Net

WebAPI - odata service adding ForeignKey
As you clarified in your comment, the reason you want to add foreign key information is because your client application is not including related entities when you query the main entity. I don't think foreign keys are the problem here. As an example, I'll use two entity types: Customer and Order. Every Customer has some number of associated Orders, so I have a navigation property on Customer called Orders that points to a collection of Orders. If I issue a GET request to /MyService.svc/Customers(1), the server will respond with all of the Customer's information as well as URLs that point to the related Order entities*. I won't, by default, get the data of each related Order within the same payload. If you want a request to Customers(1) to include all of the data of its associated Orders,

Categories : Asp Net Web Api

ASP.NET WebAPI: Generic controller for OData endpoint
You can create a custom routing convention that selects the same controller no matter what the entity set is. Example, public class CustomControllerRoutingConvention : IODataRoutingConvention { public string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext, ILookup<string, HttpActionDescriptor> actionMap) { return null; } public string SelectController(ODataPath odataPath, HttpRequestMessage request) { return "SomeFixedContrllerNameWithoutTheControllerSuffix"; } } You can register that routing convention using the following code, IList<IODataRoutingConvention> routingConventions = ODataRoutingConventions.CreateDefault(); routingConventions.Insert(0, new CustomControllerRoutingConvention()); config.Routes.MapO

Categories : Asp Net Web Api

Use camelCase for OData WebAPI query string options?
No. OData properties are case sensitive. However there is a codeplex issue open to support case insensitive property names for OData queries in web API here. Vote for it if you think it should be supported.

Categories : Wcf

WebApi Odata Windows Store App EndSaveChanges exception
Ok, so I have finally solved this. Just a recap for those who could experience the same issue. I have an Odata WebApi controller, Windows 8 Store Application using WCF Client Library, with the reference created from Add Service Reference. When trying to update (patch) a record an exception was being thrown at the EndSaveChanges. This is because for some reason Post Tunneling is enabled by default on my context. Setting this to false allowed everything to work. Context.UsePostTunneling = false; Context.IgnoreResourceNotFoundException = true;

Categories : Asp Net Web Api

WebApi OData formatter doesn't work for child elements
In OData related entities are represented as navigation links. So, if you have a customers feed, the related orders for each customer will not be part of the customers feed. Instead, they would be represented as navigation links. You can explicitly tell the OData service to expand the related entities using the $expand query option. So, if you want the related orders for each customer to be expanded, you should ask for the url ~/Customers?$expand=Orders.

Categories : Asp Net Web Api

.net WebApi OData + breeze => [Q] Unhandled rejection reasons (should be empty)
I had the same problem. As it turned out, going back to datajs 1.0.3 seemed to work. However, doing that resulted $expand to not work (the server works, but breeze doesn't handle it the navigation properties -> regardless its multiplicity). I must say, I am terrible looking for a STABLE breezejs equivalent.

Categories : Javascript

WebAPI OData 5.0 Beta - Accessing GlobalConfiguration throws Security Error
I am not sure what the exact reason for this would be, but I generally see this error when one of the nuget packages is an older version (non pre-release). Could you try upgrading all your nuget packages and see if this goes away.

Categories : Asp Net Mvc

WebAPI OData Actions Sample - Differentianting between CheckOut and CheckOutMany actions
Your observation about CheckOutMany is correct. It doesn't make sense for CheckOutMany to bind to a an entity collection as it is already taking the movie id's it has to check out as an input.

Categories : C#

Returning HTTP 403 in a WebAPI method
You might have a problem with your routing configuration. Below is a working sample. Put it in your controller and see if it works. If it doesn't check your routing with a diagnostic tool (i.e. Cobisi Routing Assistant) public string GetSomeString(int id) { // This method is not allowed! return this.Request.CreateErrorResponse(HttpStatusCode.Forbidden, "This method is not allowed!"); }

Categories : Asp Net

WebAPI in VS 2010, method not returning JSON
I just found out what was wrong. When creating my controller I didn't choose "Empty API controller" option (facepalm). After I have changed my controller to derive from ApiController class everything was working properly.

Categories : C#

Prevent webapi from returning all data from associated tables
Turn off lazy loading for the context. My best guess is it's on and the entities are loaded when the graph is serialized... Note: that's actually a good idea in a web app and I'd recommend you do it globally, so that you don't get bitten by performance issues due to lazy loading later, and always know precisely what you'll return.

Categories : Entity Framework

Returning HTTP 403 substatus from Asp.Net WebApi controller
That's because sub-statuses are not part of the HTTP spec and should not be used. If you want to send more details about the problem you encountered, take a look at Json-problem

Categories : Asp Net Web Api

Unable to initialize OData. with Breeze, Needed to support remote OData services
For OData support with Breeze you will also need the datajs library from Microsoft. More information here as well: Breeze OData

Categories : Javascript

OData in Web API Doesn't Follow OData Standard Specs
The WebAPI OData implementation does follow the OData specs. The JSON you included at the top of your question is an old OData JSON format, which is now usually referred to as "Verbose JSON". The JSON format that WebAPI is producing is the new OData JSON format for OData v3 and above. WCF Data Services will produce the same format for the "application/json" media type in v3 services. Try sending an Accept header of "application/json;odata=verbose" if you want the old format. Take a look at the spec here for an explanation of the new JSON format: http://docs.oasis-open.org/odata/odata-json-format/v4.0/csprd01/odata-json-format-v4.0-csprd01.html (Note this is the OData v4 spec, which is still not finalized, but most of what's described there about the JSON format applies to v3 as well).

Categories : Asp Net Mvc

Returning valid JSON from JSON Formatter on HTTP OK for WebAPI
Not sure what is the best practice here and may be someone from ASP.NET Web API team can answer but this works. public HttpResponseMessage Get() { return Request.CreateResponse<object>(HttpStatusCode.OK, new object()); }

Categories : C#

WebAPI - Attribute Routing breaks DELETE with WebAPI Cors?
You seem to be hitting a known issue of using CORS with Attribute Routing. Following issue is currently tracking that. http://aspnetwebstack.codeplex.com/workitem/954 This is due to httpmethod constraints that Attribute Routing creates when generating routes. Workarounds (You have couple of options here): Explicitly decorate the action with HttpOptions verb attribute too so that this constraint also gets added and your OPTIONS request can pass through. Create a custom route builder which adds OPTIONS to all routes (you can modify this behavior if your like though). Some sample code: config.MapHttpAttributeRoutes(new CustomRouteBuilder()); public class CustomRouteBuilder : HttpRouteBuilder { public override IHttpRoute BuildHttpRoute(HttpRouteValueDictionary defaults, HttpRouteV

Categories : Dotnet

Breeze, OData, and no EF
You can expose as large or as small of a surface as you want on the server. Filtering can occur either on the client via a Breeze where clause or on the server when you create an IQueryable that exposes only a subset collection of some entity type. Moreover you can also use the Breeze EntityQuery.withParameters method if you want to expose an api that is either not queryable or queryable thru semantics other than IQueryable.

Categories : Asp Net Web Api

OData Associations In C#
Instead of modeling the relationship between Product->Category with a foreign key, you could have your service model point to the product's category directly. What I mean is that instead of this: public class Product { // ... public int CategoryID { get; set; } } You could model it like this: public class Product { // ... public Category ProductCategory { get; set; } } If you set up the model this way, the WCF Data Services reflection provider should automatically create a navigation property on Product as well as the necessary association in the model.

Categories : C#

Query the web Api with OData
Are you using the right version of Web Api OData? I think this behavior you get when using the version 4... try updating your package at: Microsoft.AspNet.WebApi.OData

Categories : Entity Framework

JSONModel and OData
An FYI that might turn out to answer your question: The JSON you posted is an old JSON format of OData (now usually referred to as "JSON Verbose"). In fact, it's going away completely when OData gets formally standardized by OASIS. Part of the reason we replaced this old format is exactly what you're running into here: it's tough to consume. If the OData service you're talking to supports version 3 of the OData protocol, asking for "application/json" should return the new JSON format. You can be more explicit about this for asking for "application/json;odata=minimalmetadata". The new JSON format does not have any "d" wrapper and is structured like the JSON you expected at the top of your question. If the service you're talking to does not support V3, and you don't control the service y

Categories : IOS

OData Protocol version
The version of the WCF Data Services (5.5) is independent from the version of the protocol being used. You can have a 5.5 server that only supports up to OData v2, for example. The latest version of OData is version 3, with version 4 coming out soon. If you're using WCF Data Services as the framework for your OData server, you can set the max protocol version with the MaxProtocolVersion configuration property: // This method is called only once to initialize service-wide policies. public static void InitializeService(DataServiceConfiguration config) { // .. Other configuration goes here ... // Set the max protocol version of the server to be v3 config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V3; } (The Initial

Categories : Wcf

OData access from a DMZ server
It's very easy to handle the OData queries yourself and you can return IEnumerable, IList, PageResults or whatever. Here's an example: [HttpGet] [ActionName("Example")] public IEnumerable<Poco> GetExample(ODataQueryOptions<Poco> queryOptions) { //simulate an EF DbSet for the example var data = new Poco[] { new Poco() { id = 1, name = "one", type = "a" }, new Poco() { id = 2, name = "two", type = "b" }, new Poco() { id = 3, name = "three", type = "c" } }; var t = new ODataValidationSettings() { MaxTop = 2 }; queryOptions.Validate(t); var s = new ODataQuerySettings() { PageSize = 1 }; var results = queryOptions .ApplyTo(data.AsQueryable(), s) as IEnumerable<Poco>; return results; } public class Poco {

Categories : Wcf

TFS OData workitem get last insert id
What I did was adding a Guid to a random field that you are not using and query for that Guid afterwards. wi.Title = "New Work Item"; wi.FoundInBuild = Guid.NewGuid().ToString(); wi.Type = "Bug"; wi.Project = "TestProject"; context.AddToWorkItems(wi); context.SaveChanges(); Debug.WriteLine(String.Format("Work item created")); var createdWi = context.WorkItems.Where( d => d.FoundInBuild == wi.FoundInBuild);

Categories : Tfs

How to cache OData feed?
I have developed one library for Client side caching the data. Here are the link Please Click here jquery.cache-1.0.0

Categories : Javascript

CORS using asp.net web api 2 odata and breeze
var cors = new EnableCorsAttribute( "http://localhost:7122/", "*", "*", "DataServiceVersion, MaxDataServiceVersion" ); config.EnableCors(cors); Try adding DataServiceVersion and MaxDataServiceVersion to your EnableCorsAttribute. This worked for me. I found it here.

Categories : C#

using odata function isof with web api
We don't support isof and cast functions in web api. We instead support the new cast syntax using separate segments. Your query would look like this with the new syntax, ../Supplier?$filter=Product/namespace.ToyProduct/ratedAge eq 5

Categories : Dotnet

Breeze OData error
Generally when I see 'should be empty' it means that the promise contained a rejection that was unhandled, some other unhandled error, or a promise was simply never returned for some reason. Generally when I have this error I make sure to either console.log() the rejection reason or use something like the logger that you are using. You can do this a number of ways but this should give you the reason for rejection, provided that you aren't using a synchronous query such as executeQueryLocally - function getAll() { var query = breeze.EntityQuery.from("MuscleGroup").orderBy("Name"); // added a promise failure handler return manager.executeQuery(query).fail(queryFailed); } And add the following to your dataservice or w/e function queryFailed(error) { var msg = 'Error re

Categories : Asp Net Web Api

WCF service or OData for Windows 8 / WP8 app
If your service could potentially ever talk with clients that you do not control, WCF DS (and therefore OData) should probably be you're choice, since your service will be far more inter-operable than anything else by being part of the growing OData ecosystem. If you don't care about any client but your own, then you are presumably basing your decision on ease of development, performance, maintainability, and so on. A straight WCF Service will give you more precise control and can likely allow for performance enhancements in various ways, since you have a lot more control over what your data looks like. But it probably means more work too. WCF DS Server/Clients will make you never have to worry about serializing or deserializing data to the request or response. WCF DS Client can build

Categories : Wcf

WCF OData performance improvement
The most important part is your Expand No, It's not possible to LINQ over WCF data services with Parallel LINQ . The best way is to index over foreign keys of relations between customers and human resources and payroll tables ToArray wont takes too long Use SQL profiler and SQL execution plan to improve your performance and find bottle necks Consider creating method on your service layer and use Select method to return only columns you need Another best practice is using JSON format instead of using XML Serializer. It will decrease your response size up to 70%. Let me know if you want more information. good luck

Categories : C#

Implementing OData with custom DAL
Is it something like this you are looking for? http://msdn.microsoft.com/en-us/data/gg601461.aspx Best regards db

Categories : Wcf

OData $select not working on Web API
'Microsoft ASP.NET Web API OData' 4.0.30506 package doesn't have the $select and $expand support. To get $select and $expand support, you have to upgrade to one of our latest packages. 5.0.0-beta2 should work. Optionally, you can try our nightly builds as well to get all the latest features.

Categories : C#

ASP.NET MVC Web API and passing oData query
You can write a custom parameter binding attribute for FindOrganizationsQuery the same way we do for ODataQueryOptions and then attribute your FindOrganizationsQuery with that attribute. Some sample code below, public class CustomQueryBindingAttribute : ParameterBindingAttribute { public override HttpParameterBinding GetBinding(HttpParameterDescriptor parameter) { return new CustomQueryBinding(parameter); } internal class CustomQueryBinding : HttpParameterBinding { public CustomQueryBinding(HttpParameterDescriptor parameter) : base(parameter) { } internal class CustomQueryBinding : HttpParameterBinding { public CustomQueryBinding(HttpParameterDescriptor parameter) : base(parameter) {

Categories : C#

RequestEntityTooLarge with WCF OData client
Microsoft.Data.OData has absolutely nothing to do with any of the <bindings /> settings. <httpRuntime maxRequestLength="x" /> is going to help. This will increase the .net limits. However there is another upload limit on IIS. You will need to up the IIS limits with the following. <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="2000000000" /> </requestFiltering> </security> </system.webServer>

Categories : C#



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.