B4J Question Stop receiving from the webservice

Radisk3

Member
Licensed User
Longtime User
Hello, dear developers!

I'm having trouble understanding why the system stops receiving returns from the webservice.
I developed a procedure that I already run in another program. I'm redoing the program in B4J.
In the other system, I search for various balances in the webservice that, on average, take 60 seconds to return. In the worst cases, 120 seconds.
The same procedure in B4J simply stops receiving. It receives up to two returns and stops.
Exactly in this call "Wait For (JOB) JobDone(JOB As HttpJob)".
I put it like this, waiting, otherwise it would overload the server with dozens of calls.
So I thought it would be appropriate to make B4J wait for each request.
I have access to the server processing, the webservice, and I see it finish executing the request and return, but the project in B4J doesn't receive it.

Here's part of the process that makes the loop to call the webservice:

B4X:
    For CA = DateTime.GetYear(MI) To DateTime.GetYear(MF)
        For M = 1 To 12
            Dim DataRef As Long = DateUtils.SetDate(CA, M, 1) ' Primeiro dia do mês
'            Dim UltimoDia As Long = DateUtils.AddPeriod(DataRef, DateUtils.Period.Create(0, 1, -1)) ' Último dia do mês
            Dim UltimoDia As Long = DateUtils.AddPeriod(DataRef, PerioDoM) ' Último dia do mês
            UltimoDia = DateUtils.AddPeriod(UltimoDia, PerioDoD) ' Último dia do mês

            ' Verifica se o mês está dentro do intervalo escolhido pelo usuário
            If DataRef >= MI And UltimoDia <= MF Then
                Dim fMes As String = DateTime.Date(UltimoDia) ' Formato correto para o WS
                Status_Processo (1,"Requisitando saldo da data " & fMes)

                ' Enviar requisição para buscar os saldos do mês correspondente
                Dim JsonRequisicao As String = jsCI.Replace("¡DATAFINAL¡", fMes)
                AnoMes.Ano=CA
                AnoMes.Mes=M
                Log(CA & " - " &  M)
                'AQUI FAZ A CHAMADA AO PROCESSAMENTO
                API_WK(JsonRequisicao, "Estoque/Estoque.svc/json/BuscarSaldos")
                Wait For (JOB) JobDone(JOB As HttpJob)
                Status_Processo (1,"Saldo recebido! Processando...")
                Processa_Job(JOB)
                JOB.Release
                Sleep (5000)
            Else
                Log(CA & " - " &  M)
            End If
        Next
    Next

'Here is the procedure that executes the call.

B4X:
private Sub API_WK(Texto_da_Requisicao As String, Metodo_da_Requisicao As String)
    Dim JOB As HttpJob
    Dim Link_API As String=txWSWK.Text
 
    JOB.Initialize("BuscaWK", Me)
    JOB.PostString(Link_API & Metodo_da_Requisicao, Texto_da_Requisicao)
    JOB.GetRequest.SetContentType("application/json")
    JOB.GetRequest.SetContentEncoding("gzip, deflate")
    JOB.GetRequest.Timeout = 240000 ' 4 minutos
End Sub

Does anyone have any idea what I'm doing wrong?
 

Radisk3

Member
Licensed User
Longtime User
'JOB' is declared in method API_WK, not in the calling code. I presume the calling code is waiting for something that wasn't started, and therefore waits forever.
Hello my friend!

Thank you for your reply.
You are right.
I had also tried to leave the entire procedure within the same routine but without success when I left the executable running.
But I discovered that my mistake was another. I left the Httpjob JobDone procedure active in the project.
For some reason, when I ran the executable on the server, it processed the Jobdone routine instead of the one I left within the procedure.
I left everything in the same routine and removed Jobdone and it worked.

Thank you for your reply.
 
Upvote 0
Top