asp.net web api2 - Web API 2 Odata V4 PATCH return 404 -


i have controller :

using system.web.http; using system.web.odata;  public class invrecipientautoinvoicecontroller : odatacontroller     {         // get: odata/invrecipientautoinvoice         [enablequery]         public iqueryable<inv_recipientautoinvoice> getinvrecipientautoinvoice()         {             return db.inv_recipientautoinvoice.where(a=>a.companynumber == companynumber);         }      [acceptverbs("patch", "merge")]        public ihttpactionresult patch([fromodatauri] int recipientnumber , [fromodatauri] int recipienttype, delta<inv_recipientautoinvoice> patch)         {             // xxxx update code         }     } 

the works , result , can sort them. when patch request, 404 error , patch request :

request url: http://localhost:61240/odata/invrecipientautoinvoice(recipientnumber%3d443%2crecipienttype%3d400)

   request method: patch 
  • response body :

{ "error":{ "code":"","message":"no http resource found matches request uri 'http://localhost:61240/odata/invrecipientautoinvoice(recipientnumber=443,recipienttype=400)'.","innererror":{ "message":"no action found on controller 'invrecipientautoinvoice' matches request.","type":"","stacktrace":"" } } }

  • request body :
{"invoiceline1description":"32132"} 

i using in asp.net web project (not mvc),

the register :

config.mapodataserviceroute( routename: "odataroute", routeprefix: "odata", model: builder.getedmmodel()); 

what missing?

@yaniv

it seems want use built-in routing conventions patch entity composite keys. however, the built-in routing conventions doesn't support composite keys.

you can either custom own routing conventions ( see here ) or use attribute routing.

attribute routing simple , easy use. need put odatarouteattribute on patch action, should work.

[acceptverbs("patch", "merge")] [odateroute("invrecipientautoinvoice(recipientnumber={recipientnumber},recipienttype={recipienttype})"] public ihttpactionresult patch([fromodatauri] int recipientnumber , [fromodatauri] int recipienttype, delta<inv_recipientautoinvoice> patch) {      // xxxx update code } 

thanks.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -