Hi,
I am using an AppService dynamic Web Api, and can also specify the HttpGet attribute in the interface. I am wondering if there is (or will be) any support for the Route attribute as well, like this:
public interface IContactAppService : IApplicationService
{
[HttpGet]
[Route("get_contacts")]
Task<List<ContactListDto>> GetContacts();
}
If not, is there another way to specify a custom route e.g. using the DynamicApiControllerBuilder? Thanks and regards, Robert
10 Answer(s)
-
0
Yes, it should support any attribute can be used in a web api controller. Note: For attribute routing, you should enable it first, as you know (<a class="postlink" href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2#enable">http://www.asp.net/web-api/overview/web ... i-2#enable</a>)
-
0
Thanks, but this is not working yet. The only place I find which has access to HttpConfiguration is in Initialize() of the WebApiModule. I have added "MapHttpAttributeRoutes()" there:
Configuration.Modules.AbpWebApi().HttpConfiguration.MapHttpAttributeRoutes(); //Automatically creates Web API controllers for all application services of the application DynamicApiControllerBuilder .ForAll<IApplicationService>(typeof(CosmosMoonApplicationModule).Assembly, "app") .Build();
But the api (using e.g. Postman) still only responds to "/GetContacts", not "/get_contacts". I also see this reflected in the generated service proxy:
serviceNamespace.getContacts = function(ajaxParams) { return abp.ajax($.extend({ url: abp.appPath + 'api/services/app/contact/GetContacts', type: 'GET', data: {} }, ajaxParams)); };
Note also that there is no camelCase conversion as claimed. Is there a better place to call "MapHttpAttributeRoutes()" ?
thanks...
-
0
oops, ignore my comment about camelCase. Of course it is the javascript-method which gets renamed to camelCase, not the url path!
-
0
I am still having no success. Inserting: Configuration.Modules.AbpWebApi().HttpConfiguration.MapHttpAttributeRoutes(); as mentioned above did not help.
Maybe this information is useful: It is an ASP.NET Zero application which we purchased from you.
We would like the services we add to become more REST-oriented, which is why the Route-Attribute is important to us.
Thanks and regards, Robert
-
0
Please note that I am referring to service interfaces in the Application project, not controllers in the WebApi project.
-
0
We are also experiencing issues with the Route attribute. Regardless of the attribute, the service still answers on the method name and not on the defined route. We tried all suggestions on this thread, and the page you point to, to no avail.
This is a pretty standard ASP feature, and it's working well for services we defined as APIController. Please advise how to further debug, and hopefully enable this functionality.
-
0
We are also having trouble with the Route attribute. Regardless of the value we specify, methods keep responding in the method name and not in the defined route.
This is a pretty standard API feature, and it's working well for the two methods we have defined outside the ABP scope (as ApiController). Please advise on how to further debug, and hopefully enable this critical functionality
-
0
Hi,
Can you create Github issue for it, then we also test and fix it if needed.
Thanks.
-
0
Hi, has an issue been created for this on github?
-
0
I created now: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1000">https://github.com/aspnetboilerplate/as ... ssues/1000</a>