Must a webservice be in it's own module?

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Must a webservice be in it's own module?

Postby gk1441607435 » Mon Nov 14, 2016 12:04 pm

I have a REST-Service in a form using ws_read and ws_create. Besides I'm not using the plugin RESTFull Webservices. The webservice is working fine as I expected. The only problem is that I had to move the webservice in an own module! I was not able to run the webservice in the main solution. I moved the form with the webservice using 'move form' to move it from one module to an other. It's working in every submodule. Only in the main module I receive status '503 Service unavailable'.

Now my question: Is it possible to run a webservice in a main solution or do I really have to create an own module for the webservice?

Thanks for your help

Gregory
gk1441607435
 
Posts: 14
Joined: Mon Sep 07, 2015 8:30 am

Re: Must a webservice be in it's own module?

Postby patrick » Mon Nov 14, 2016 1:17 pm

I think it has to be a module, yes. Design wise that is also way better. A webservice is a stateless and the idea is to have it fire up as fast as possible. Loading a solution with 843 forms, scripting scopes etc. etc. is just not advisable.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Must a webservice be in it's own module?

Postby gk1441607435 » Mon Nov 14, 2016 2:55 pm

Hello Patrick

Thank's for your fast reply.

I agree that it's better located in an own module. I was just curious if it's possible to have it the main solution.
By the way, you said:
A webservice is a stateless and the idea is to have it fire up as fast as possible. Loading a solution with 843 forms, scripting scopes etc. etc. is just not advisable.

Does this mean, the whole solution with all it's modules would be loaded when a webservice is called in the main solution? The following behaviour is strange to me. When I call the webservice (in a module!) e.g. with a GET-request, first ws_authenticate() is called, second ws_read() and then at last onSolutionOpen()? Why is onSolutionOpen() the last function that is called and not the first? And why is it called every time a webservice is requested? Does this mean the module is created every time a webservice is requested?
Maybe this is the reason why it can't be in the main solution.


Gregory
gk1441607435
 
Posts: 14
Joined: Mon Sep 07, 2015 8:30 am

Re: Must a webservice be in it's own module?

Postby patrick » Mon Nov 14, 2016 5:46 pm

For every request, a client from the headless client pool loads the given solution (part of the URL you call). It runs through the onSolutionOpen, a possible authenticate and then executes whatever ws_ method required. Then it unloads the solution again. I'm not a core Servoy developer, but at least that is my understanding of how that works ;-). So a webservice module should only have a bunch of forms for the possible endpoints and the core logic of the data model (relations, calculations, table events, entity methods), that should come from yet another module that the webservice shares with the main solution.

In any case: calling a big solution to just return an address is a bad idea. It should fire up in milliseconds, not seconds.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: Must a webservice be in it's own module?

Postby gk1441607435 » Mon Nov 14, 2016 6:11 pm

Hello Patrick

Thanks for the answer!
I also suddenly realized today that servoy starts a headless client when I make a request, because there appeared a headless client in the active client list in eclipse. Your answer made more clear what happens.
O.K. I still don't know if it's possible to run a webservice in a main solution or if I really have to create an own module for the webservice, but it doesn't matter, because it makes no sence to run a webservice in a main solution.

Thanks

Gregory
gk1441607435
 
Posts: 14
Joined: Mon Sep 07, 2015 8:30 am

Re: Must a webservice be in it's own module?

Postby patrick » Mon Nov 14, 2016 6:18 pm

I still don't know if it's possible to run a webservice in a main solution or if I really have to create an own module for the webservice


I think that is by design (so added on purpose, not because it couldn't be done), to avoid

because it makes no sence to run a webservice in a main solution
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests

cron