Service method not found

Hi,
I have defined in the studio a service.
I was able to login and get the token.
When I call my service I am getting the error:

{
    "error": "Service method not found",
    "details": "crm_RegistrationService.test()"
}

here is my source: https://bitbucket.org/avifatal/cuba-crm/src/6d88a53d586797dd8e740cbc3bb42e3f46342eb5/modules/?at=master

image

What am I missing here?

Thanks

Hi,

you have to expose the service methods as endpoints in the application. To do that, add a rest-services.xml into the root path of the web module which contains:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<services xmlns="http://schemas.haulmont.com/cuba/rest-services-v2.xsd">
    <service name="crm_RegistrationService">
        <method name="test"/>
    </service>
</services>

and reference this file in the web-app.properties file in order to let CUBA pick up the configuration:

cuba.rest.servicesConfig = +com/platform/crm/rest-services.xml

Here’s the update app: Crm.zip (87.8 KB)

This can all be done via Studio as well automatically.

See also the docs: https://doc.cuba-platform.com/manual-6.10/rest_api_v2_services_config.html

Bye
Mario

1 Like

@mario Thanks you, I was missing the web property.
I have another few more short questions about the subject if I may.

  1. in .net core, the webapi rest service manager understands everything naturally.
    let’s say you want to define a service.
    you just do, and that’s it. no XML configurations for that.
   [Route("api/[controller]")]
    [ApiController]
    public class TodoController : ControllerBase
    {
          [HttpGet("{id}")]
          public ActionResult<TodoItem> GetById(long id)
          {

          }
    }
    //GET /todo/1

I assume java has a library that may act like that (much much less configurations), is it possible in the context of cuba to implement?

  1. Question about the token, once I did login via the rest service, the token life is very short. and I need to refresh it very often. is there a mecanism that the token can live for longer time?

  2. I want to allow customers to register to the system, I have a CustomerEntity and needs to have a relation to UserEntity of type customer with role customer. Do you have a manual how to implement that?

Thanks for your time
Avi

Hi,

what you showed there is an HTTP endpoint controller in C#. There is an equivalent to that in the Java / Spring world, but it is not a Service. A Service is normally the business logic abstraction, that does not deal with HTTP endpoints and so on. The fact that it is possible in CUBA to expose it as an HTTP endpoint, is more of an edge / ease-of-use case, not so much the default way. This is also why you have to explicitly expose the methods as endpoints in configuration files.

A Spring MVC controller looks 95% like your example above. You can see the docs to this here: https://doc.cuba-platform.com/manual-6.10/rest_api_v2_custom_controllers.html

But it would be interesting to see which problem you are trying to solve here. Since there is a generic REST API already available out of the box: https://doc.cuba-platform.com/manual-6.10/rest_api_v2.html a lot of use-cases (not all) can be tackled through this probably, at least as a starting point…

Bye
Mario

@mario, Thank you. I will explore both of them. I think that the cuba api is the spring one with all the configuration that im “complaining about”.

Can you please answer number 3?

  1. I want to allow customers to register to the system, I have a CustomerEntity and needs to have a relation to UserEntity of type customer with role customer. Do you have a manual how to implement that?