Xojo.Net.HttpSocket in webapp

I can’t fire the PageReceived event in a webapp that queries a REST webservice (but in the desktop version it fires correctly).

I have read some posts about Xojo.Net.HttpSocket, from which I assumed there was problems (at least a few years ago).

I ask if anyone confirms that the problems are still there.

if the problems, instead, have been resolved (as I hope), I ask if someone can give me suggestions to obtain the data required to the web service.

thank you

Xojo.Net.HttpSocket should work in a web app. If you’re running the web app on Linux, make sure the libsoup library is installed.

thank you, Paul.
my web app runs in Windows standalone.
any suggestions about the reason why the PageReceived event doesn’t fire?

On Windows, I just put a Xojo.Net.HTTPSocket on a page and called the Eddie’s Electronics web service with it from a button using this code:

EESocket.Send("GET", "http://demos.xojo.com/EEWS/index.cgi/api/GetAllCustomers")

And the PageReceived event was called and the correct data was provided.

Are you sure your socket is not going out of scope? Can you narrow it down to a small sample?

You should also at least be implementing the Error event, in case something is going wrong. For diagnostic purposes, I’d suggest implementing:
AuthenticationRequired (in case it’s requesting a username & password)
HeadersReceived (perhaps you’re getting a HTTP status with no content)

[quote=410094:@Paul Lefebvre]On Windows, I just put a Xojo.Net.HTTPSocket on a page and called the Eddie’s Electronics web service with it from a button using this code:

EESocket.Send(“GET”, “http://demos.xojo.com/EEWS/index.cgi/api/GetAllCustomers”)

And the PageReceived event was called and the correct data was provided.

Are you sure your socket is not going out of scope? Can you narrow it down to a small sample?[/quote]

thank you,
with your procedure I connected and also received the data (both from EEWS and from my own test WS).

in my project, I had defined the socket in the page, as a subclass of a defined Xojo.Net.HttpSocket object (with its events) out of the page.

was this my mistake? is it not possible?
should I define the object Xojo.Net.HttpSocket (with its events) on every page where I need it?

Subclassing is fine.

It can be convenient to put the socket on the page as its events will have access to page methods and properties.

If you create your socket in code using New then you’d want to make sure the socket does not go out of scope so it should probably be a property of the page.

I just tried both these methods and they worked fine.

I’m not able to intercept the result from the PageReceived event.

I call a WebService using Xojo.Net.HttpSocket inside a webcontainer and, following the flow with the debugger, the PageReceived event ends with the expected result (e.g., an array that I have also tried to save in a webcontainer property ).

But, when I try to use the data in the webcontainer, I get NilObjectException.
I understand this depends on the asynchronous execution of the socket, but I’m not able to solve my problem.

Can someone insert an example that can help me?

I’ve temporarily resolved with a cycle after WebService call.

something like this (in a button Action):

MySocketGetRequest (, “http://…/Api/Get…”)

Dim b As Boolean = False

While b = False
If ar.Ubound > -1 Then b = True
Wend

< here the array is populated>

is it a good solution?

[quote=410705:@natale pappalardo]I’ve temporarily resolved with a cycle after WebService call.

something like this (in a button Action):

MySocketGetRequest (, “http://…/Api/Get…”)

Dim b As Boolean = False

While b = False
If ar.Ubound > -1 Then b = True
Wend

< here the array is populated>

is it a good solution?[/quote]
You’ll freeze up your entire app for all users doing it that way.

[quote=410662:@natale pappalardo]I’m not able to intercept the result from the PageReceived event.

I call a WebService using Xojo.Net.HttpSocket inside a webcontainer and, following the flow with the debugger, the PageReceived event ends with the expected result (e.g., an array that I have also tried to save in a webcontainer property ).

But, when I try to use the data in the webcontainer, I get NilObjectException.
I understand this depends on the asynchronous execution of the socket, but I’m not able to solve my problem.

Can someone insert an example that can help me?[/quote]
So the debugger stops and tells you where the exception is and looking at the debugger variables can you tell which one you are using is nil?

thanks Greg,

why I will block the entire app for all users, if the cycle is in the calling session?

[quote=410928:@natale pappalardo]While b = False
If ar.Ubound > -1 Then b = True
Wend[/quote]
Because of this…

While b = False If ar.Ubound > -1 Then b = True Wend
That’s a tight loop that doesn’t yield the current thread. Now, you could yield the thread, but you must consider that you may end up with a thread context change. You won’t see the problems unless you are running more than one session and the likelihood of problems goes up with every additional user.

[quote=410938:@Greg O’Lone]Because of this…

While b = False If ar.Ubound > -1 Then b = True Wend
That’s a tight loop that doesn’t yield the current thread. Now, you could yield the thread, but you must consider that you may end up with a thread context change. You won’t see the problems unless you are running more than one session and the likelihood of problems goes up with every additional user.[/quote]

thanks for the clarification.
but how can I intercept, in a webpage, the result of the socket PageReceived event, before the program flow proceeds with the following instructions?

[quote=410948:@natale pappalardo]thanks for the clarification.
but how can I intercept, in a webpage, the result of the socket PageReceived event, before the program flow proceeds with the following instructions?[/quote]
Well… the correct answer here is that you shouldn’t. The problem with doing it this way is that you run the real risk of locking up your entire app for 30 seconds if the server you are calling doesn’t respond.

The correct way to do this is to implement the PageReceived event and finish your processing there. The thing to remember is that asynchronous events from things like sockets and timers (where the responses always come “later”) all fire on the main thread. That is, when the event fires the framework can’t tell which session made the request. You will have to keep track of that and then set up a SessionContext object before trying to access any session specific data.

thanks for your help.

is this the right way? https://www.dropbox.com/s/cohcs1uxzjnlaez/WebTest_20181022.7z?dl=1