3

at the moment I have two projects. A "Backend" MVC project for managing information (working completely fine). I am now building a "Frontend" MVC project. I am using the provided demos from ASP NET ZEROS.

i have created app services and within my Backend app services, I can access the app services and the methods within that services without any issues like below.

var _listingService = abp.services.app.listings;

I am trying to do the exact same in my other project but unfortunately, I am unable to access the services. abp object is available but services is undefined

enter image description here

May I ask, how do I get access to my app services from another application? I think something else has to be configured before I can use it, but I am not entirely sure what.

Update: 2020-08-26

I was able to add this line

<script src="~/AbpServiceProxies/GetAll?type=jquery" type="text/javascript"></script>

This created a proxy from my controller to javascript. I can then link my controllers to my appservices. But I am hoping going from javascript straight to appservices.

Master
  • 2,038
  • 2
  • 27
  • 77
  • 1
    Are you describing a _disconnected_ architecture? For instance I would deploy the backend MVC project independently as the _API_ and the front end should reference it via _http_ calls so that the two could be deployed and scaled independently. If you intend for it to be _connected_ so the whole lot is deployed as a single unit, that can be done too, but then what was the point of splitting it into 2 different MVC projects? – Chris Schaller Aug 27 '20 at 00:33
  • @ChrisSchaller Not quite a disconnected project. The two projects never communicate to each other. It's really a question of why can I access appservices from one project but not the other. – Master Aug 27 '20 at 00:37
  • In your backend application (Web API), have you enabled CORS? This is a basic requirement to allow it to be accessed through another domain. See more about it here: https://learn.microsoft.com/pt-br/aspnet/core/security/cors?view=aspnetcore-3.1 – Silvair L. Soares Aug 27 '20 at 13:19
  • @Master could you clarify why ```AbpServiceProxies/GetAll``` doesn't work for you? It declares abp.serives.app.* objects and gives you access right to the Application Services bypassing controllers. – Alexey Merson Sep 02 '20 at 09:57
  • 2
    Your question is not very clear. Please provide us more useful code snippets or share some repository that contains the same issue you're getting. – André Andrade Sep 02 '20 at 12:45

1 Answers1

1

you can add

Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder
    .ForAll<IApplicationService>(Assembly.GetAssembly(typeof(yourModule)), "jquery")
    .Build();

, More info in https://aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API?searchKey=Proxy

Washyn Acero
  • 174
  • 1
  • 8