Web Connection
Persisting a wwJsonServiceClient
Gravatar is a globally recognized avatar based on your email address. Persisting a wwJsonServiceClient
  Ron Jasper
  All
  Jun 7, 2025 @ 09:54am

Hi Rick, I'm using the wwJsonServiceClient to make calls between webconnection sites and it's working great. I'm wondering if I can get my response times down by only creating the wwJsonServiceClient object once and then reusing it throughout the application. I believe this is possible but I'm not sure the best way to handle this as my site endpoints are all functions and I don't think I want to create a PUBLIC object but rather a GLOBAL object. Is that correct? If so, should I create the object in either the init or onload function of myappmain.prg? Or is there a better way? Thanks again.

Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Rick Strahl
  Ron Jasper
  Jun 8, 2025 @ 08:29am

That's not going to make a difference. Creating objects that don't have a lot of state is cheap in FoxPro. It's not worth the hassle of trying to use a single instance. In fact it's counter productive in this case because these calls have some state you set on them that you then have to unset or risk using the wrong settings from a previous request.

The recommended way for anything that relates to Http calls in general is to use a new instance for any requests you make. This ensures you always start from a clean slate and don't have left over POST data, or Http settings or result values etc. The cleanup is more expensive than creating a new instance and reconfiguring.

If you have a lot of set up code that you're trying to avoid, create a factory method either on your process class or some other global location that's easy to access. For those you can use a Process Class method, a Server class method or a global UTF in your function library - lots of ways to do this.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Ron Jasper
  Rick Strahl
  Jun 8, 2025 @ 12:13pm

Thanks again Rick. I did put the following in the Protected Function OnInit

this.oResources.AddProperty("oCitRestSvc", CREATEOBJECT("wwJsonServiceClient"))

and then I call it in my procedure file:

loProxy = Server.oResources.oCitRestSvc
loResponse = loProxy.CallService("https://loadsw.com/lsLineAdded.cit",loFromLsAction,"PUT")

When I read the webconnection request logs (repeating the endpoint call); the one where I set up the object in the OnInit is about 10 ms faster than creating the object wwJsonServiceClient object each time. Since the loProxy object never changes is this approach ok?

Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Rick Strahl
  Ron Jasper
  Jun 8, 2025 @ 12:34pm

No that's definitely not right!

You're making HTTP requests that are going to take hundreds of times longer than the object creation and that are variable in time. The variance you observe is from the Http calls. And 10ms is margin of error in the best of times for requests against Web Connection servers.

This is entirely unnecessary premature optimization...

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Ron Jasper
  Ron Jasper
  Jun 8, 2025 @ 01:09pm

Thanks Rick, I'll go in and make the changes right away.

Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Ron Jasper
  Ron Jasper
  Jun 8, 2025 @ 01:16pm

Do I need to release the objects after creating and using them in my procedure:

    loProxy = CREATEOBJECT("wwJsonServiceClient")
    loResponse = loProxy.CallService("https://myserver.com/myfunction.cit",loFromLsAction,"PUT")
Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Ron Jasper
  Ron Jasper
  Jun 8, 2025 @ 01:39pm

My guess is I don't need to release the objects as I would expect that to happen automatically when the function ends. One little thing that puzzles me: When I haven't made a call to the webconnection server for a quite a while (running in com mode), the first call reads as high as 3.02 in the server request log. Subsequent calls take between .19 and .34 I am using a dedicated cpu hosted server, Is there any way I can mitigate this? And thanks again, I've fixed the wwJsonServiceClient call in my function and create one each time. The speed is great.

Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Rick Strahl
  Ron Jasper
  Jun 8, 2025 @ 04:15pm

IIS will shut down application pools that are idle for a certain amount of time. When they start back up the first request can be much slower than 'normal' requests. There's initial Web site startup (ie. IIS process loading), and the COM servers and VFP loading for the first time, plus your code compiling and VFP warming up.

You can configure that in the Application Pool configuration in IIS. The default is 20 minutes of no requests to the server.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Persisting a wwJsonServiceClient
  Ron Jasper
  Rick Strahl
  Jun 9, 2025 @ 04:22am

Thanks Rick, I'll check that out. Is there any downside to setting it quite low?

© 1996-2025