Android Question HttpJob - Bad Request 400

Slacker

Active Member
Licensed User
Longtime User
Nothing of special: i have a REST WCF Service and i call some method through HttpJob object.
Everything works perfectly ... after a while (30-40 min) i get - AND JUST ALWAYS FOR THE SAME METHODS I CALL - the Http 400 Error (Bad Request). If i call other WCF service methods, all is fine... it seems that just Always with the same 2 methods calling i get, after a while, this error; it does not related to POST/GET http type calling, because all the other methods i call after i get that error response, are both POST OR GET and they work fine.

Here is a little snippet code of the method i get error:

B4X:
Sub HttpGetUsers(showLoading As Boolean, resetPage As Boolean)
httpAgent.Initialize("GetUsers", Me)
If (showLoading) Then
ProgressDialogShow(Utils.GetAppString("Loading_Msg"))
Else
ProgressBar1.Visible = True
End If
If (resetPage) Then usersListPageIndex = 1
httpAgent.PostString(Utils.GetConfigFile.get("EndpointAddress") & "GetUsersList", "pagindex=" & usersListPageIndex)
Utils.SetCookiesHeader(httpAgent.GetRequest)
End Sub

As you can see, every call i set a cookies header for my stuff; i've checked the cookies and the header string is always ok.... this error appears just with this method, and it's pretty strange.....

"httpAgent" variable is declared in the activity Globals and is initialized every request as you can see.

Is there something i'm wronging ?

Thank you ! ;)
 

Slacker

Active Member
Licensed User
Longtime User
HttpJob is the type.

I'm monitoring this to check on server the request through wireshark and verify the headers... this is pretty strange... it seems that request, in some momenti in time, is corrupted... and just that specific request... on the server does not seems to raise any exception... :/
 
Upvote 0

Slacker

Active Member
Licensed User
Longtime User
Uhm.... should i redeclare it every time before use you suggest ?
 
Upvote 0

Slacker

Active Member
Licensed User
Longtime User
I know that "Dim x As y" instantiate a new object; but the "Initialize()" method what role should have ?
Often compiler tells: "The object should be initialized before use".

If i instantiate an object with the simply declaration, why it's mandatory to call "Initialize()" ? Could explain me better and quickly the role of this method and its need in B4A world ? Thank you Erel.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Dim x as y => Creates a new instance of y.
However if there is an Initialize method then it should be called before the object can be used. This is not a strict rule for library objects. It is a strict rule for B4A classes. You must call Initialize before you can access any method of the object.

So why isn't the object initialized automatically when you call Dim x As Y ????

Because you can also assign an initialized object to x:
B4X:
Dim x As Y = List1.Get(20)
 
Upvote 0

Slacker

Active Member
Licensed User
Longtime User
Perfect, that's clear now. So, this is a pattern in B4A that compiler use to know to behave when it meets this type of sequence to generate correct code.

Calling several times "Initialize()" to the same declarated object (as i did in HttpAgent) means to reuse the same object i think...

The drawbacks in this situation, could be unexpected behavior cause by the lack of default initialization of the default constructor that is called when we type "Dim x As y"..... i think this could be the problem related to my issue as above... isn'it ?
 
Upvote 0
Top