Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Using Web Api from external windows service #655


User avatar
0
patrickglaudemans created

Hi,

I'm developing a .net windows service. I want to connect this service to my zero application layer. The application layer still follows the initial setup. Api controllers are therefore dynamically created.

  1. I want to connect to the application layer with REST. What is the best way to set that up with ExternalBearer token etc.
  2. I want to connect an angular file upload call to my application service. Therefore, I have to enhance the Web Api wrapper controller. Should I then manually create the web api controller? How should i do that? I want to create something like this: public class FilesController : ApiController { [HttpPost] // This is from System.Web.Http, and not from System.Web.Mvc public async Task<HttpResponseMessage> Upload() { if (!Request.Content.IsMimeMultipartContent()) { this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType); } (...) etc.

Thanks for all your help in advance - hope others can gain something from it as well!

Regards, p


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    1. This is a sample console application that uses application services remotely: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/blob/master/ConsoleRemoteWebApiCall/CallApiFromConsole/Program.cs">https://github.com/aspnetboilerplate/as ... Program.cs</a>

    How to run?

    Create a demo from <a class="postlink" href="http://www.aspnetzero.com/">http://www.aspnetzero.com/</a> (if you have already a demo and know your credentials, skip this step) Run the application, enter your credentials and you will see the role list!

    But this uses cookie based authentication. For token based auth, you need to get/set headers instead of using cookies. If you can test your web api layer from Postman (<a class="postlink" href="http://www.aspnetzero.com/Documents/Development-Guide#token-based-authentication">http://www.aspnetzero.com/Documents/Dev ... entication</a>), then you can make it working in C#. It's straightforward. I will prepare a class to make this easier. You can follow this issue: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/681">https://github.com/aspnetboilerplate/as ... issues/681</a> But, you can do it yourself by getting <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.Web.Api/WebApi/Client/AbpWebApiClient.cs">https://github.com/aspnetboilerplate/as ... iClient.cs</a> as start point. You can even contribute to the framework if you implement it.

    1. You should create a regular web api controller like ProfileController in your solution (it's used to upload profile picture). Because uploading a file is web specific stuff. If you want, you can create app service method which gets a byte[] as image. Then you can use this service from controller.

    Have a nice day.