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

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

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#

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 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

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

.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 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

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

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 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#

Web Api Odata action methods using Get verb return 404
OData has better semantics for exposing streams for an entity. You can either use named streams or Media Link Entry (MLE). Read about it here and here. Named streams seem to suit your scenario better. I have a sample here that shows how to use extensibility points in web API OData to do named streams.

Categories : C#

web api odata action method to return image
I think the problem is with closing the FileStream. Do not close the stream as Web API's hosting layers take care of closing it. Also, you need not set the content-length explicitly.StreamContent sets this for you. [HttpPost] public HttpResponseMessage Picture([FromODataUri] int key) { var folderName = "App_Data/Koala.jpg"; string path = System.Web.HttpContext.Current.Server.MapPath("~/" + folderName); StreamContent sc = new StreamContent(new FileStream(path,FileMode.OpenRead)); HttpResponseMessage response = new HttpResponseMessage(); response.Content = sc; response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg"); response.StatusCode = HttpStatusCode.OK; return response; }

Categories : C#

JayData. OData v.3 Action POST parameters received as null
JayData expects service operations published via WebGet attribute right now. You are right about the OData standard, it does expecti the params of POST operations in URL parameter, but it's strange because both classic WCF and WebAPI uses params in the body... it's a standard, so it must be followed. In case you cannot use WebGet attribute, feel free to propose the feature that supports POST invoke method: JayData backlog JayData Github issue list

Categories : C#

WebApi Action filter called twice
I have a suspicion, that this strange behavior can be fixed by either overriding AllowMultiple property of filter and returning false, or applying AttributeUsage attribute with AllowMultiple set to false too (this influences on default implementation of AllowMultiple property of filter. At least in our project this helped (we have filters injected via Autofac).

Categories : Asp Net Mvc

webapi route with controller and action
Usually default values are recommended values. You don't need to change this unless you have special requirements. api/{controller}/{controller}/{id} is a non-sense because you don't have to display two times the name of the controller in the URL. {action} is not everytime needed (if use of GET/PUT...). You may want to create api/{controller}/{action}/{id} as a second route or specify {action} in the default route as UrlParameter.Optional.

Categories : Asp Net Web Api

WebAPI function invoked before controller action
What I need is to have some kind of handler function, which is triggered every time when service is called, before my flow enters into controller method. You could write a custom message handler. For example as shown in the MSDN article: public class ApiKeyHandler : DelegatingHandler { public string Key { get; set; } public ApiKeyHandler(string key) { this.Key = key; } protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { if (!ValidateKey(request)) { var response = new HttpResponseMessage(HttpStatusCode.Forbidden); var tsc = new TaskCompletionSource<HttpResponseMessage>(); tsc.SetResult(response);

Categories : C#

Delete operation in my webAPI controller where id is a filename
I don't necessarily see a problem with using a string as the ID, depending on the scope of what you're doing. If you're managing files within the same folder on a Windows PC (server), for instance, you can't have more than one file with the same name. So filename is unique enough. If you are concerned about that, you can store a list of the files you're managing in a database, and assign a unique ID (say, an int) to each file. That way you can reference that value on the backend when you do your deletes.

Categories : Asp Net

Overload WebAPI controller action doesn't work with viewmodels?
By default, ASP.NET Web API selects an action method based on the HTTP verb and the action method parameters. In the second case, you have two action methods that can handle GET and they have one parameter each. When Web API tries to find an action method (more info here) for your GET, it will find both the methods. You can follow RPC-style URI if you must have action methods like these. Add a mapping in WebApiConfig.cs like this. public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "RpcStyle", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new

Categories : Asp Net Mvc

Posting json to mvc 4 WebApi controller action. Why doesn't it deserialize my array?
Are your properties in TradeOffer really private? If so, those need to be public. In addition, public List<TradeOffer> TradeOffers { get; set; } should be public List<TradeOffer> TradeOffer { get; set; } OR you should change the name to the plural version in your JSON collection

Categories : C#

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

How do I get WebAPI to accept a complex object as its argument for a DELETE HTTP verb without using C# attributes?
MyClass is a complex type and is bound from the request body with ASP.NET Web API. HTTP semantics do not allow a request body for DELETE and for this reason, you will not be able to post a request body with DELETE using Angular. To be exact, this is not an issue with Angular but most of the browsers do not send a body with AJAX DELETE requests.

Categories : C#

MVC4 WebApi Controller Post Action with Dispose Pattern causes Multiple Actions Found Exception
Its much easier to understand the solution when you correctly interpret the error message: When making the choice to the request, the WebApi Action Selector cannot decide between the Dispose() and Post() methods. (Which seems pretty daft in itself). So the error is effectively asking us to help make this decision for it. My preferred option is to use the NonActionAttribute class on the Dispose() Action method. This is a clear and transparent instruction to the Action Selector to not consider the Dispose method in deciding where to route the request. [NonAction] public new void Dispose() { Dispose(true); GC.SuppressFinalize(this); } The other option is to change the accessor of the Dipose() method to protected, but that's just not as obvious.

Categories : C#

Delete action without scaffolding
in statuses_controller.rb you should have destroy action def destroy @status = Status.find(params[:id]) # or find(params[:status_id]) depends on how route is built @status.destroy respond_to do |format| format.html { redirect_to statuses_url } format.json { head :no_content } end end change the redirect_to statuses_url to redirect_to :back it will get you back from where your request started or redirect_to root_url for home page.

Categories : Ruby On Rails

Do I need to specify ON DELETE NO ACTION on my Foreign Key?
You can remove the keywords (this is the default) ON DELETE NO ACTION Would be better to specify those actions ON DELETE CASCADE Here's more info this: http://msdn.microsoft.com/en-us/library/aa933119%28v=sql.80%29.aspx You'll have to write a trigger to make sure child row's aren't deleted, as I dont think SQL Server has this option of ON DELETE RESTRICT

Categories : SQL

ROR delete action not working
Did you mention the method as delete in your views? If you are using Rails 4, you should do: <%=link_to 'Destroy', post_path(post), method: :delete, data: { confirm: 'Are you sure?' } %> In Rails 3: <%=link_to 'Destroy', post_path(post), method: :delete, confirm: 'Are you sure?' %>

Categories : Ruby On Rails

about delete EKEvent, when action = EKEventEditViewDelegate
Implement the EKEventViewDelegate protocol then check for the delete event with... -(void) eventViewController:(EKEventViewController *)controller didCompleteWithAction:(EKEventViewAction)action { if (action == EKEventViewActionDeleted) { // Update unique event ID to core data & change text of button to new _itemReminder = NULL; _part.reminderID = NULL; _savedEventFound = NO; [_reminderButton setTitle: @"New" forState: UIControlStateNormal]; } }

Categories : Iphone

Delete action and destroy method
delete is method of HTTP protocol. destroy is the action of your controller. Route with delete HTTP method leads to destroy action. To edit this routes and make delete HTTP method lead to delete action (for example), you should edit config/routes.rb file.

Categories : Ruby On Rails

how to move to the dialog box immediate to the above of ROW for which delete action is performed
I agree that default position of Delete dialog is not good. I posted many ways how one can change the behavior. For example the old answer provide the demo which do almost what you need. Another answer demonstrate how to create context menu from the buttons of navigator bar. Combination of both solutions allows to create the best comfort for the user. The user can use context menu to see all actions from the navigation menu without need to scroll the grid. Choosing of Add/Edit or Delete items of menu created dialog on the same position.

Categories : Jquery

MVC: Javascript confirm for delete action not working
You need to cancel the default behaviour of the browser when the user clicks cancel. You can do this by returning the result of confirmDeleteAction() to your <a> tag: @Html.ActionLink( "Delete", "Delete", new {id=notification.Id, typeId=notification.TypeId}, new {onclick="return confirmDeleteAction()"}) For clarity, I added the return keyword to your onclick handler which will return the result of confirmDeleteAction() to the browser - true = perform the default behaviour of the link false = do nothing

Categories : Javascript

cakePHP 2.3 delete cached view for action
You can provide some conditional criteria in callbacks to delete the specific cached views. Reinitialize a new $cacheAction in callback with the specific view set the time to 0. Ref: Official Link

Categories : Cakephp

Action sheet UIButton to process delete
You have to implement the UIActionSheet Delegate methods actionSheet:didDismissWithButtonIndex: will work perfectly EDIT Adding setEditing:YES inside the UIActionSheet delegate method will only place the tableView into editing mode, not commit the deletion. I don't know how you are retrieving the rows you wish to delete, but Editing mode only allows a single row selection. I think what may be better for what you wish to accomplish is manipulate your didSelectRowAtIndexPath method to mark each row for deletion, and either add the selected indices to an array, or mark the rows with a checkmark. Then in the UIActionSheet delegate method when the users hits 'OK', place the deletion logic, either use the indices array or iterate through the cells to find the ones you selected for deleti

Categories : IOS

Update , Delete data from 2 table with one action zf2
You can just use sql join or and like this: DELETE FROM table1, table2 WHERE table1.id = (constant) AND table1.id = table2.id Where constant is the id value that you want to delete form both table. This has been answered in this question already by the way.

Categories : PHP

Issue in rails 4.0 with creating a link_to for a delete action
If you use (which is adviced) resources: a) Your action for deleting records should be named destroy. b) Game is searched for with :id parameter: def destroy @game = Game.find(params[:id]) @game.destroy redirect_to :action => 'index' end c) Your link should be: <%= link_to 'Delete', t, method: :delete %> since the path is the same as for the show action, the only thig that changes is HTTP method.

Categories : Ruby On Rails



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