Base solution for your next web application
Open Closed

Hosting WebAPI and Dynamic WebAPI #1320


User avatar
0
finallyfreeguy created

I need to host WebAPI and Dynamic WebAPI controllers in standalone windows form application. Is there any sample or document to do this?


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

    There is no such a sample. But there is a WPF & Windows Forms demo: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/AbpWpfDemo">https://github.com/aspnetboilerplate/as ... AbpWpfDemo</a> And also there are docs on the web shows how to use web api as self hosted. I think you can do it by combining these informations.

  • User Avatar
    0
    finallyfreeguy created

    Good starting point... [https://github.com/aspnetboilerplate/aspnetboilerplate/issues/561])

  • User Avatar
    0
    hikalkan created
    Support Team

    Oh, I even forgot it :) Thanks.

  • User Avatar
    0
    finallyfreeguy created

    I have an authorization problem with application service. I can successfully get result from application service but if I use AbpAuthorize attribute with the same service it returns unAuthorizedRequest true.

    I'm using Content-Type and Authorization (Bearer) headers that explained in [http://www.aspnetboilerplate.com/Pages/Documents/Zero/Startup-Template#token-based-authentication]) document.

    Returned json :

    {
      "success": false,
      "result": null,
      "error": {
        "code": 0,
        "message": "No user logged in!",
        "details": null,
        "validationErrors": null
      },
      "unAuthorizedRequest": true
    }
    

    Meanwhile Tenant/GetTenants service returns the result without any problem but my application service is unauthorized. Edit : Ahh sorry. GetTenants is an anonymous function.

  • User Avatar
    0
    finallyfreeguy created

    Any advice?

  • User Avatar
    0
    finallyfreeguy created

    From AbpAuditLogs...

    Abp.Authorization.AbpAuthorizationException: Kullanıcı girişi yapılmamış!
       konum: Abp.Authorization.AuthorizeAttributeHelper.<AuthorizeAsync>d__13.MoveNext() D:\Halil\GitHub\aspnetboilerplate\src\Abp\Authorization\AuthorizeAttributeHelper.cs içinde: satır 29
    --- Özel durumun oluşturulduğu önceki konumdan başlayan yığın izlemesinin sonu ---
       konum: System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       konum: System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       konum: Nito.AsyncEx.AsyncContext.<>c__DisplayClass3.<Run>b__1(Task t)
       konum: System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke()
       konum: System.Threading.Tasks.Task.Execute()
    --- Özel durumun oluşturulduğu önceki konumdan başlayan yığın izlemesinin sonu ---
       konum: System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       konum: System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       konum: Nito.AsyncEx.AsyncContext.Run(Func`1 action)
       konum: Abp.Authorization.AuthorizeAttributeHelper.Authorize(IEnumerable`1 authorizeAttributes) D:\Halil\GitHub\aspnetboilerplate\src\Abp\Authorization\AuthorizeAttributeHelper.cs içinde: satır 45
       konum: Abp.Authorization.Interceptors.AuthorizationInterceptor.Authorize(IEnumerable`1 authorizeAttributes) D:\Halil\GitHub\aspnetboilerplate\src\Abp\Authorization\Interceptors\AuthorizationInterceptor.cs içinde: satır 86
       konum: Abp.Authorization.Interceptors.AuthorizationInterceptor.Intercept(IInvocation invocation) D:\Halil\GitHub\aspnetboilerplate\src\Abp\Authorization\Interceptors\AuthorizationInterceptor.cs içinde: satır 43
       konum: Castle.DynamicProxy.AbstractInvocation.Proceed()
       konum: Abp.Domain.Uow.UnitOfWorkInterceptor.PerformSyncUow(IInvocation invocation, UnitOfWorkOptions options) D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs içinde: satır 53
       konum: Abp.Domain.U...
    

    AuthorizeAttributeHelper class throws an exception in AuthorizeAsync method. Line number is 29.

    if (!AbpSession.UserId.HasValue)
                {
                    throw new AbpAuthorizationException(LocalizationManager.GetString(AbpConsts.LocalizationSourceName, "CurrentUserDidNotLoginToTheApplication"));
                }
    

    AbpSession.UserId has no value! I dont know why...

  • User Avatar
    0
    finallyfreeguy created

    I think its not possible to use session in self hosted environment...

    [http://stackoverflow.com/questions/11347807/httpselfhostserver-and-httpcontext-current])

  • User Avatar
    0
    finallyfreeguy created

    Any suggestion?