i'm developing asp.net web api c# , .net framework 4.5.1.
i have strange behaviour. can access 2 following routes can't reach third , fourth. error:
no http resource found matches request uri. no action found in 'externalcodes' driver match application.
[httpput] [route("api/externalcodes/setcodesasused")] public httpresponsemessage setcodesasused(list<string> codes) { return changecodesstatus(codes, 3); } [httpput] [route("api/externalcodes/setcodesasunused")] public httpresponsemessage setcodesasunused(list<string> codes) { return changecodesstatus(codes, 1); } [httpput] [route("api/externalcodes/setbatchcodesasused")] public httpresponsemessage setbatchcodesasused(int batchid) { return changebatchcodesstatus(batchid, 3); } [httpput] [route("api/externalcodes/setbatchcodesasunused")] public httpresponsemessage setbatchcodesasunused(int batchid) { return changebatchcodesstatus(batchid, 1); }
all in same class.
this webapiconfig
class:
public static class webapiconfig { public static void register(httpconfiguration config) { // web api configuration , services // web api routes config.maphttpattributeroutes(); config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); config.routes.maphttproute( name: "productionorderactionapi", routetemplate: "api/productionorders/{action}/{ordernumber}", defaults: new { controller = "productionorders", ordernumber = routeparameter.optional }); config.routes.maphttproute( name: "batchesactionapi", routetemplate: "api/batches/{action}", defaults: new { controller = "batches" }); config.routes.maphttproute( name: "linesactionapi", routetemplate: "api/lines/{action}", defaults: new { controller = "lines" }); config.routes.maphttproute( name: "externalcodesactionapi", routetemplate: "api/externalcodes", defaults: new { controller = "externalcodes" }); config.routes.maphttproute( name: "codesactionapi", routetemplate: "api/codes", defaults: new { controller = "codes" }); config.routes.maphttproute( name: "aggregationsactionapi", routetemplate: "api/aggregations", defaults: new { controller = "aggregations" }); } }
these nuget packages:
<?xml version="1.0" encoding="utf-8"?> <packages> <package id="antlr" version="3.5.0.2" targetframework="net451" /> <package id="bootstrap" version="3.3.2" targetframework="net451" /> <package id="dotnetzip" version="1.9.3" targetframework="net451" /> <package id="entityframework" version="6.1.3" targetframework="net451" /> <package id="jquery" version="2.1.3" targetframework="net451" /> <package id="jquery.validation" version="1.13.1" targetframework="net451" /> <package id="log4net" version="2.0.3" targetframework="net451" /> <package id="microsoft.aspnet.mvc" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.razor" version="3.2.3" targetframework="net451" /> <package id="microsoft.aspnet.web.optimization" version="1.1.3" targetframework="net451" /> <package id="microsoft.aspnet.webapi" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.webapi.client" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.webapi.client.es" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.webapi.core" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.webapi.core.es" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.webapi.webhost" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.webapi.webhost.es" version="5.2.3" targetframework="net451" /> <package id="microsoft.aspnet.webpages" version="3.2.3" targetframework="net451" /> <package id="microsoft.jquery.unobtrusive.ajax" version="3.2.3" targetframework="net451" /> <package id="microsoft.jquery.unobtrusive.validation" version="3.2.3" targetframework="net451" /> <package id="microsoft.web.infrastructure" version="1.0.0.0" targetframework="net451" /> <package id="modernizr" version="2.8.3" targetframework="net451" /> <package id="newtonsoft.json" version="6.0.8" targetframework="net451" /> <package id="ninject" version="3.2.2.0" targetframework="net451" /> <package id="ninject.mvc5" version="3.2.1.0" targetframework="net451" /> <package id="ninject.web.common" version="3.2.3.0" targetframework="net451" /> <package id="ninject.web.common.webhost" version="3.2.3.0" targetframework="net451" /> <package id="webactivatorex" version="2.0.6" targetframework="net451" /> <package id="webgrease" version="1.6.0" targetframework="net451" /> </packages>
this strange, because routes in same controller.
any idea happening?
the links access actions are:
http://myspecialserver:53827/api/externalcodes/setbatchcodesasused http://myspecialserver:53827/api/externalcodes/setcodesasused
you accessing action on controller without parameter.
in call parameter codes
null. working because list<string>
-datatype nullable.
[httpput] [route("api/externalcodes/setcodesasused")] public httpresponsemessage setcodesasused(list<string> codes) { return changecodesstatus(codes, 3); }
the second link same -> batchid null. int non-nullable type error.
anyway should change route if have parameters (especially if non-nullable).
[route("api/externalcodes/setbatchcodesasunused/{batchid}")]
this route expects id part of call. has advantage, know, resource changing.
the call this:
http://myspecialserver:53827/api/externalcodes/setbatchcodesasused/1
Comments
Post a Comment