Is there a way to place a HttpJob into a Class - I would really like to make my .NET web service API fully contained in the class similar to how .NET would do it (as best I can) which means ideally I would set properties, invoke the Call method which would build the XML request, submit it via the HttpJob, and parse the SOAP / JSON (depending on the class) and set the properties of the class based on the response (you know, how .NET would do it)
This is what the class example looks with the ValidateUser method embedded in the class
It feels like the problem is that control returns back to my activity before the class fully processes the HttpJob and therefore the response is not fully parsed in time for what happens next in the activity after the call to ValidateUser.
Is there a way to execute the HttpJob blocking thread executing and not return from the class call until the httpjob is finished?
This is what the class example looks with the ValidateUser method embedded in the class
B4X:
Sub Class_Globals
'
' Attributes
'
Public ClientBuild As Int
Public IndLaborCode As String
Public EmployeeNumber As String
Public BarcodePrinterPath As String
Public BarcodeSystemType As Int
Public AutoIndirectAfterTA As Boolean
Public WarnErrorNegativeInventory As String
Public PasswordMinLength As Int
Public PasswordRepeatingCharLimit As Int
Public PasswordHistoryLimit As Int
Public PasswordResetRequired As Boolean
Public PasswordDays As Int
Public PasswordExpireDate As String
Public EmployeeClearConstant As Int
Public CurrentPrinter As String
Public DefaultPrinter As String
Public HomeFacility As String
Public TimeZoneAddSubtract As String
Public TimeZoneOffset As Int
Public DefaultMenu As String
Public Password As String
Public UserName As String
Public UserID As String
Public IsSystemAdmin As Boolean
Public ForceInvTransactions As Boolean
Public NumericMenus As Boolean
Public ClientIdent As String
Public ServerLoginsDisabled As Boolean
Public ServerLoginDMessage As String
Public ServerSystemVersion As Int
Public AuthFlags As String
'
' Controls
'
Public ParseError As Boolean
Public ParseErrorMsg As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
ParseError = False
ParseErrorMsg = ""
End Sub
public Sub RequestXML As String
Return $"<?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>
<ValidateUser xmlns="http://tempuri.org/">
<Environment>
<ClientBuild>${ClientBuild}</ClientBuild>
<Password>${Password}</Password>
<UserID>${UserID}</UserID>
</Environment>
</ValidateUser>
</soap:Body>
</soap:Envelope>"$
End Sub
'public Sub getRequestJob As HttpJob
'
' Dim j As HttpJob
'
' j.Initialize("",Main)
' j.PostString(Globals.WebServerPath & "server.asmx", RequestXML )
' j.GetRequest.SetContentType("text/xml; charset=utf-8")
' j.GetRequest.SetHeader("SOAPAction",$""http://tempuri.org/ValidateUser""$)
'
' Return j
'
'End Sub
public Sub ValidateUser
Dim j As HttpJob
j.Initialize("",Me)
j.PostString(Globals.WebServerPath & "server.asmx", RequestXML )
j.GetRequest.SetContentType("text/xml; charset=utf-8")
j.GetRequest.SetHeader("SOAPAction",$""http://tempuri.org/ValidateUser""$)
wait for (j) jobdone(j As HttpJob)
If j.Success Then
ParseXml(j.GetString)
Else
ParseErrorMsg = "Error Communicating with Web Server: " & j.ErrorMessage
ParseError = True
End If
j.Release
End Sub
public Sub ParseXml(XmlString As String)
Dim x2m As Xml2Map
x2m.Initialize
'
' extract base document root
'
Dim root As Map
If x2m.Parse(XmlString) Is Map Then
root = x2m.Parse(XmlString)
Else
ParseError = True
ParseErrorMsg = "Missing Document Root"
Return
End If
'
' extract base document root
'
'Log(root)
Dim envelope As Map
If root.Get("Envelope") Is Map Then
envelope = root.Get("Envelope")
Else
ParseError = True
ParseErrorMsg = "Soap Envelope Missing"
Return
End If
'
' extract soap body
'
Dim body As Map
If envelope.Get("Body") Is Map Then
body = envelope.Get("Body")
Else
ParseError = True
ParseErrorMsg = "Soap Body Missing"
Return
End If
'
' extract Environment from Response
'
Dim EnvironmentResponse As Map
If body.Get("ValidateUserResponse") Is Map Then
EnvironmentResponse = body.Get("ValidateUserResponse")
Else
ParseError = True
ParseErrorMsg = "Environment Response is missing from Soap Envelope"
Return
End If
'
' extract environment from response
'
Dim Environment As Map
If EnvironmentResponse.Get("Environment") Is Map Then
Environment = EnvironmentResponse.Get("Environment")
Else
ParseError = True
ParseErrorMsg = "Environment is missing from Environment Response"
Return
End If
'
' Extract Individual Attributes
'
ClientBuild = Environment.Get("ClientBuild")
IndLaborCode = Environment.Get("IndLaborCode")
EmployeeNumber = Environment.Get("EmployeeNumber")
BarcodePrinterPath = Environment.Get("BarcodePrinterPath")
BarcodeSystemType = Environment.Get("BarcodeSystemType")
AutoIndirectAfterTA = Environment.Get("AutoIndirectAfterTA")
WarnErrorNegativeInventory = Environment.Get("WarnErrorNegativeInventory")
PasswordMinLength = Environment.Get("PasswordMinLength")
PasswordRepeatingCharLimit = Environment.Get("PasswordRepeatingCharLimit")
PasswordHistoryLimit = Environment.Get("PasswordHistoryLimit")
PasswordResetRequired = Environment.Get("PasswordResetRequired")
PasswordDays = Environment.Get("PasswordDays")
PasswordExpireDate = Environment.Get("PasswordExpireDate")
EmployeeClearConstant = Environment.Get("EmployeeClearConstant")
CurrentPrinter = Environment.Get("CurrentPrinter")
DefaultPrinter = Environment.Get("DefaultPrinter")
HomeFacility = Environment.Get("HomeFacility")
TimeZoneAddSubtract = Environment.Get("TimeZoneAddSubtract")
TimeZoneOffset = Environment.Get("TimeZoneOffset")
DefaultMenu = Environment.Get("DefaultMenu")
Password = Environment.Get("Password")
UserName = Environment.Get("UserName")
UserID = Environment.Get("UserID")
IsSystemAdmin = Environment.Get("IsSystemAdmin")
ForceInvTransactions = Environment.Get("ForceInvTransactions")
NumericMenus = Environment.Get("NumericMenus")
ClientIdent = Environment.Get("ClientIdent")
ServerLoginsDisabled = Environment.Get("ServerLoginsDisabled")
ServerLoginDMessage = Environment.Get("ServerLoginDMessage")
ServerSystemVersion = Environment.Get("ServerSystemVersion")
AuthFlags = Environment.Get("AuthFlags")
End Sub
It feels like the problem is that control returns back to my activity before the class fully processes the HttpJob and therefore the response is not fully parsed in time for what happens next in the activity after the call to ValidateUser.
Is there a way to execute the HttpJob blocking thread executing and not return from the class call until the httpjob is finished?