Invoking a Web Service with progressbar that shows the state of the transmission.

energypf

Member
Licensed User
Longtime User
Hello, I am new to the forum. I have created a web method on a Web Service that passing credentials back to me a file (<GetReportResult> base64Binary </ GetReportResult>), since these files can also get to 1Mb, I would like to know if there is a possibility to display a progressbar that displays the download status of the response from the webservice. Thanks in advance. :BangHead:
 

energypf

Member
Licensed User
Longtime User
I used HttpClient and HttpRequest using HttpUtil2 gives me an internal server error. With HttpClient everything works fine, except that there is no event Progress in order to know the progress.
 
Last edited:
Upvote 0

energypf

Member
Licensed User
Longtime User
There is an example to invoke a Web Service using HttpUtils, but it does not work, is there any other example that creates the XML and then placed in the Web Service?
 
Upvote 0

energypf

Member
Licensed User
Longtime User
I solved using HttpUtils2, but I had to change the Job class, the Sub PostBytes flatly. In fact, it did not work because it was set:

SetHeader ("Content-Type", "text / xml; charset = utf-8")
SetHeader ("SOAPAction", "http://yourserver/SoapAction")


If you do these two are set Header does not work the call to the web service.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you do not need to edit HttpJob for these changes.

You can set the headers like this:
B4X:
Dim J As HttpJob
J.Initialize(...)
J.PostBytes(...)
J.GetRequest.SetHeader(...)
J.GetRequest>SetHeader(...)

About the download progress.

You can track the progress by following these steps:
- Add a reference to RandomAccessFile library
- Add these two variables to HttpUtils2Service Sub Process_Globals:
B4X:
Public countingStream As CountingOutputStream
Public totalLength As Long
- Change hc_ResponeSuccess to:
B4X:
Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
   totalLength = Response.ContentLength
   countingStream.Initialize(File.OpenOutput(TempFolder, TaskId, False))
   Response.GetAsynchronously("response", countingStream, True, TaskId)
End Sub

- In your code add a timer and check HttpUtils2Service.countingStream.Count every few seconds.
This will return the number of downloaded bytes.
 
Upvote 0

energypf

Member
Licensed User
Longtime User
PERFECT!! I moved the SetHeader in the activity and works, with regard to the progress bar I used this method: HttpUtils2Service.progressSub = "DownloadProgress" and subsequently with the Sub DownloadProgress (tmp As ProgressStatus) I control the progression. Thank you so much
 
Upvote 0

imbault

Well-Known Member
Licensed User
Longtime User
How do you do that for setting headers in code ?


when I'm trying to code :

Dim job1 As HttpJob
Job1.Initialize(job1,Me)

job1.GetRequest.SetHeader("Content-Type", "text/xml; charset=utf-8")

I have a JAVA.lang.nullPointerException Error

Thanks
 
Upvote 0

energypf

Member
Licensed User
Longtime User
Dim InviaAWebService As HttpJob
Dim RequestSoapXML As String

InviaAWebService.Initialize("DownloadEvent",Me)

Url1 = "https://www.xxxxxxx.it/xxxxxx.asmx"

RequestSoapXML = _
"<?xml version='1.0' encoding='utf-8'?>" & _
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" & _
"<soap:Body>" & _
"<Metodo xmlns='http://xxxxxx.it/'>" & _
"<Variable>Test</Variable>" & _
"</Metodo>" & _
"</soap:Body>" & _
"</soap:Envelope>"

InviaAWebService.PostString(url1,RequestSoapXML)
InviaAWebService.GetRequest.SetHeader("Content-Type", "text/xml; charset=utf-8")
InviaAWebService.GetRequest.SetHeader("SOAPAction", "http://xxxxxxx.it/SoapMetod")
 
Upvote 0

tamayo461

Member
Licensed User
Longtime User
error

'Activity module
Sub Process_Globals

Dim job2 As HttpJob
Dim url As String
url = "http://www.concesionesdeaseo.com/ServicioConsulta/lib/servicio/SERDatos.asmx"
Dim RequestSoapXML As String

End Sub

Sub Globals
Dim etxRespuesta As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("Main")

RequestSoapXML = _
"<?xml version='1.0' encoding='utf-8'?>" & _
"<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'>" & _
"<soap12:Body>" & _
"<ConsultarResponse xmlns='Servicio'>" & _
"<ConsultarResult>string</ConsultarResult>" & _
"</ConsultarResponse>" & _
"</soap12:Body>" & _
"</soap12:Envelope>"
job2.Initialize(job2,Me)
job2.PostString(url,RequestSoapXML)
job2.GetRequest.SetHeader("Content-Type", "text/xml; charset=utf-8")
job2.GetRequest.SetHeader("Servicio/Consultar" , "http://www.concesionesdeaseo.com/ServicioConsulta/lib/servicio/SERDatos.asmx/Consultar")
Msgbox(job2.JobName,"titulo")

End Sub

Sub JobDone (job As HttpJob)
'Log("JobName = " & job.JobName & ", Success = " & job.Success)
'Msgbox("JobName = " & job.JobName & ", Success = " & job.Success,"")
If job.Success = True Then
Msgbox(job.GetString,"")
Else
'Log("Error: " & job.ErrorMessage)
ToastMessageShow("Error: " & job.ErrorMessage, True)
End If
job.Release
End Sub

----------------------------------------------------------------

Where is the error????

Internal Server Error

and the JobName in the image...
:BangHead:
 

Attachments

  • SC20121128-144901.png
    SC20121128-144901.png
    45.3 KB · Views: 283
Upvote 0
Top