Base solution for your next web application
Open Closed

Using Web Api from external windows service #655

patrickglaudemans created


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)
  • 0
    hikalkan created
    Support Team


    1. This is a sample console application that uses application services remotely: <a class="postlink" href=""> ... Program.cs</a>

    How to run?

    Create a demo from <a class="postlink" href=""></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=""> ... 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=""> ... issues/681</a> But, you can do it yourself by getting <a class="postlink" href=""> ... 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.