Web Connection
** Solved ** Is there a trick to change the value of ohttp.nConnectTimeout at run time without changing west-wind code
Gravatar is a globally recognized avatar based on your email address. ** Solved ** Is there a trick to change the value of ohttp.nConnectTimeout at run time without changing west-wind code
  Alejandro A Sosa
  All
  Jun 12, 2021 @ 07:53am

Hi,

An application calls a west-wind server rest process with this code:

loProxy	    = CREATEOBJECT("wwJsonServiceClient")
loParamDown = loProxy.CallService(lcPaydayLicenseURL+"RegisterBusinessGroup.plx",loParamUp,"POST")

When this code runs, loProxy.CallService calls FUNCTION CreatewwHttp(loHttp) which in turn creates this.oHttp = CREATEOBJECT("wwHttp") which has a default value of ohttp.nConnectTimeout = 30.

Is there a trick to change the value of ohttp.nConnectTimeout at run time without modifying the west-wind code?

******* Solution ******** As Rick suggests in his code, I subclassed wwJsonServiceClient to modify CallService by adding a fourth parameter lnConnectTimeout and adjust ohttp.nConnectTimeout as requested.

Thank you very much,

Alex

Gravatar is a globally recognized avatar based on your email address. re: ** Solved ** Is there a trick to change the value of ohttp.nConnectTimeout at run time without changing west-wind code
  Rick Strahl
  Alejandro A Sosa
  Jun 12, 2021 @ 11:47am

No, no, no .... don't add it to the method signature.

Either:

  • Override the CreatewwHttpObject() method and add the timeout
  • Call CreatewwHttPObject() then the set loClient.oHttp.nConnectTimeout = 2

The whole point of the CreatewwHttpObject() method is that you get access to the oHttp instance so you can set properties without having to re-expose most Http related properties on the client again.

loClient = CREATEOBJECT("MyServiceClient")
loClient.CreatewwHttpObject()
loClient.oHttp.nConnectTimeout = 2

lvResult = loClient.CallMethod(...)

Inside of a handler method you can do:

FUNCTION MyServiceCall

IF this.oHttp = null)
   CreatewwHttpObject()
ENDIF

*** Method specific
this.oHttp.nConnectTimeout = 2

lvResult = this.CallMethod()

RETURN lvResult

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: ** Solved ** Is there a trick to change the value of ohttp.nConnectTimeout at run time without changing west-wind code
  Alejandro A Sosa
  Rick Strahl
  Jun 12, 2021 @ 02:10pm

Thanks for the help Rick. The code ended up like this:

loProxy = CREATEOBJECT("wwJsonServiceClient")
loProxy.CreatewwHttp()
loProxy.oHttp.nConnectTimeout = 1
loParamDown = loProxy.CallService(lcPaydayLicenseURL+"RegisterBusinessGroup.plx",loParamUp,"POST")

I use a timeout of 1 to avoid delay if the server is down because a timeout of 0 seems to act as if were of 30.

When the server is down there is about a 4 to 5 second delay at THIS.OnHttpPostConnect(hHTTPResult) in HTTPGetEx function.

Thanks again.

Alex

Gravatar is a globally recognized avatar based on your email address. re: ** Solved ** Is there a trick to change the value of ohttp.nConnectTimeout at run time without changing west-wind code
  Rick Strahl
  Alejandro A Sosa
  Jun 12, 2021 @ 02:17pm

Yes the minimum timeout is somewhere between 2-3 seconds and is determined by the TCP/IP timeouts in the internal WinInet implementation that these tools use. So setting anything less than 2 is not going to be any quicker than that.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: ** Solved ** Is there a trick to change the value of ohttp.nConnectTimeout at run time without changing west-wind code
  Alejandro A Sosa
  Rick Strahl
  Jun 12, 2021 @ 02:23pm

Thanks Rick.

Alex

© 1996-2024