Android Question How to Call Asmx Web service in B4A

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have successfully created Android Apps using Web API with the help of below link.I would like to know to do the same for Asmx Web Services (CRUD operation).Please help

 

sanjog shakya

Member
Licensed User
Longtime User
Here you can start. I have been so confused when I have started project using Asmx webservice. But at the end I found solution.

Call Asmx or Wcf webservices from B4x:
Private Sub LoadProgressUpdate(FY As String)
    Dim job As HttpJob
    Dim xml As String = File.ReadString(File.DirAssets,"get_progress_update.xml")
    xml = xml.Replace("$query$",FY)
    job.Initialize("MyJob",Me)
    job.PostString(API,xml)
    job.GetRequest.SetHeader("SOAPAction", $""http://tempuri.org/IServiceReport/get_progress_update""$)
    job.GetRequest.SetHeader("User-Agent", "Apache-HttpClient/4.5.2 (Java/1.8.0_181)")
    job.GetRequest.SetContentType("text/xml; charset=utf-8")
    ProgressDialogShow2("Retreving Physical Progress data...",False)
    Wait For (job) JobDone (j As HttpJob)
    ProgressDialogHide
    If j.Success Then
        Dim response As String = j.GetString
        Dim JsonOut As String = Generic.xmlGetTagContent(response,"get_progress_updateResult")
        'Log(JsonOut)
        JsonOut = JsonOut.Replace("
","")
     
        Dim Json As JSONParser
        Json.Initialize(JsonOut)
        Dim mylist As List
        mylist.Initialize
        mylist = Json.NextArray
     
        Dim dt As List
        dt.Initialize
     
        Dim totalNew As Int, totalCO As Int, totalCCA As Double, _
             totalDetailedSurvey As Int, totalPPRCompleted As Int, _
              totalPPROngoing As Int, totalPPRAgreement As Int, _
               totalConstructionStarted As Int, _
            totalProjectCompleted As Int, totalachievedCCA As Double, Totalprogress As Double, TotalTarget As Int
     
        'For i = 0 To mylist.Size -1
        Dim index As Int
        For Each m As Map In mylist
            index = ShowProgress(progressbar_op)
            Sleep(50)
            Dim new As Int = m.Get("no_is_new")
            Dim co As Int = m.Get("no_carried")
            Dim total As Int = new + co
            dt.Add(Array(m.Get("districtname"),total,m.Get("no_is_new"),m.Get("no_carried"),Round2(m.Get("tot_cca"),0), _
                        m.Get("no_detailed_survey"),m.Get("no_ppr_completed"),m.Get("no_ppr_ongoing"), _
                        m.Get("no_ppr_agreement"),m.Get("no_construction_started"),Round2(m.Get("avg_const_progress"),2), _
                        m.Get("no_project_completed"),Round2(m.Get("achieved_cca"),0)))        
            totalNew = totalNew + m.Get("no_is_new")
            totalCO = totalCO + m.Get("no_carried")
            totalCCA = totalCCA + m.Get("tot_cca")
            totalDetailedSurvey = totalDetailedSurvey + m.Get("no_detailed_survey")
            totalPPRCompleted= totalPPRCompleted + m.Get("no_ppr_completed")
            totalPPROngoing = totalPPROngoing + m.Get("no_ppr_ongoing")
            totalPPRAgreement = totalPPRAgreement + m.Get("no_ppr_agreement")
            totalConstructionStarted = totalConstructionStarted + m.Get("no_construction_started")
            totalProjectCompleted = totalProjectCompleted + m.Get("no_project_completed")
            totalachievedCCA = totalachievedCCA + m.Get("achieved_cca")
            Totalprogress = Totalprogress + m.Get("avg_const_progress")
            TotalTarget = TotalTarget + total
        Next
        dt.Add(Array("Total",TotalTarget,totalNew,totalCO,Round2(totalCCA,0),totalDetailedSurvey,totalPPRCompleted,totalPPROngoing,totalPPRAgreement,totalConstructionStarted,Round2(Totalprogress/8,2),totalProjectCompleted,Round2(totalachievedCCA,0)))
        dgv.SetData(dt)
        'cell alignment
        SetCellAlignment_OP
        'xui.MsgboxAsync(xmlGetTagContent(response,"ReadTableSQLResult"),"B4x")
        HideProgress(progressbar_op, index)
    Else
        ToastMessageShow("No Respone. Please check your Internet Connection",True)
        'xui.MsgboxAsync(j.ErrorMessage,"B4x")
    End If
    j.Release
End Sub

Some of the variable area listed which as used above (Highlighted bold and underlined) :
API = "http://***.com.np/Service.asmx"

"get_progress_update.xml"
get_progress_update.xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:get_progress_update>
         <!--Optional:-->
         <tem:fiscalyear>$query$</tem:fiscalyear>
      </tem:get_progress_update>
   </soapenv:Body>
</soapenv:Envelope>

This xml part is taken from the asmx webservice.

The response can be checked using Postman or ReadyAPI.
At last read the content within the result part in output xml.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Here you can start. I have been so confused when I have started project using Asmx webservice. But at the end I found solution.

Call Asmx or Wcf webservices from B4x:
Private Sub LoadProgressUpdate(FY As String)
    Dim job As HttpJob
    Dim xml As String = File.ReadString(File.DirAssets,"get_progress_update.xml")
    xml = xml.Replace("$query$",FY)
    job.Initialize("MyJob",Me)
    job.PostString(API,xml)
    job.GetRequest.SetHeader("SOAPAction", $""http://tempuri.org/IServiceReport/get_progress_update""$)
    job.GetRequest.SetHeader("User-Agent", "Apache-HttpClient/4.5.2 (Java/1.8.0_181)")
    job.GetRequest.SetContentType("text/xml; charset=utf-8")
    ProgressDialogShow2("Retreving Physical Progress data...",False)
    Wait For (job) JobDone (j As HttpJob)
    ProgressDialogHide
    If j.Success Then
        Dim response As String = j.GetString
        Dim JsonOut As String = Generic.xmlGetTagContent(response,"get_progress_updateResult")
        'Log(JsonOut)
        JsonOut = JsonOut.Replace("&#xD;","")
    
        Dim Json As JSONParser
        Json.Initialize(JsonOut)
        Dim mylist As List
        mylist.Initialize
        mylist = Json.NextArray
    
        Dim dt As List
        dt.Initialize
    
        Dim totalNew As Int, totalCO As Int, totalCCA As Double, _
             totalDetailedSurvey As Int, totalPPRCompleted As Int, _
              totalPPROngoing As Int, totalPPRAgreement As Int, _
               totalConstructionStarted As Int, _
            totalProjectCompleted As Int, totalachievedCCA As Double, Totalprogress As Double, TotalTarget As Int
    
        'For i = 0 To mylist.Size -1
        Dim index As Int
        For Each m As Map In mylist
            index = ShowProgress(progressbar_op)
            Sleep(50)
            Dim new As Int = m.Get("no_is_new")
            Dim co As Int = m.Get("no_carried")
            Dim total As Int = new + co
            dt.Add(Array(m.Get("districtname"),total,m.Get("no_is_new"),m.Get("no_carried"),Round2(m.Get("tot_cca"),0), _
                        m.Get("no_detailed_survey"),m.Get("no_ppr_completed"),m.Get("no_ppr_ongoing"), _
                        m.Get("no_ppr_agreement"),m.Get("no_construction_started"),Round2(m.Get("avg_const_progress"),2), _
                        m.Get("no_project_completed"),Round2(m.Get("achieved_cca"),0)))       
            totalNew = totalNew + m.Get("no_is_new")
            totalCO = totalCO + m.Get("no_carried")
            totalCCA = totalCCA + m.Get("tot_cca")
            totalDetailedSurvey = totalDetailedSurvey + m.Get("no_detailed_survey")
            totalPPRCompleted= totalPPRCompleted + m.Get("no_ppr_completed")
            totalPPROngoing = totalPPROngoing + m.Get("no_ppr_ongoing")
            totalPPRAgreement = totalPPRAgreement + m.Get("no_ppr_agreement")
            totalConstructionStarted = totalConstructionStarted + m.Get("no_construction_started")
            totalProjectCompleted = totalProjectCompleted + m.Get("no_project_completed")
            totalachievedCCA = totalachievedCCA + m.Get("achieved_cca")
            Totalprogress = Totalprogress + m.Get("avg_const_progress")
            TotalTarget = TotalTarget + total
        Next
        dt.Add(Array("Total",TotalTarget,totalNew,totalCO,Round2(totalCCA,0),totalDetailedSurvey,totalPPRCompleted,totalPPROngoing,totalPPRAgreement,totalConstructionStarted,Round2(Totalprogress/8,2),totalProjectCompleted,Round2(totalachievedCCA,0)))
        dgv.SetData(dt)
        'cell alignment
        SetCellAlignment_OP
        'xui.MsgboxAsync(xmlGetTagContent(response,"ReadTableSQLResult"),"B4x")
        HideProgress(progressbar_op, index)
    Else
        ToastMessageShow("No Respone. Please check your Internet Connection",True)
        'xui.MsgboxAsync(j.ErrorMessage,"B4x")
    End If
    j.Release
End Sub

Some of the variable area listed which as used above (Highlighted bold and underlined) :
API = "http://***.com.np/Service.asmx"

"get_progress_update.xml"
get_progress_update.xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:get_progress_update>
         <!--Optional:-->
         <tem:fiscalyear>$query$</tem:fiscalyear>
      </tem:get_progress_update>
   </soapenv:Body>
</soapenv:Envelope>

This xml part is taken from the asmx webservice.

The response can be checked using Postman or ReadyAPI.
At last read the content within the result part in output xml.
to create XML Body and Read responses from the service, use XML2MAP
Sample (sorry spanish)
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
to create XML Body and Read responses from the service, use XML2MAP
Sample (sorry spanish)
Thanks for reply...

I have tried below code but its showing as error.Please help to solve this issues

** Activity (productionentry) Create (first time) **
** Activity (productionentry) Resume **
ResponseError. Reason: Internal Server Error, Response: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.Xml.XmlException: Root element is missing.

at System.Xml.XmlTextReaderImpl.Throw(Exception e)

at System.Xml.XmlTextReaderImpl.ParseDocumentContent()

at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()

at System.Xml.XmlReader.MoveToContent()

at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()

at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()

at System.Web.Services.Protocols.SoapServerProtocol.Initialize()

at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)

--- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
** Activity (productionentry) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **


Code : -
Code:
Public Sub WSCallSoapURL(URL As String, Parameters As String) As ResumableSub
    Dim Result As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString (URL, Parameters)
        j.GetRequest.SetHeader("Content-Type","text/xml")
        j.GetRequest.SetHeader("Content-length", Parameters.Length)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        Else
            ToastMessageShow("¡Hummm...!",False)
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return Result
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("ProductionEntry")
    WSCallSoapURL("http://103.76.188.138:85/StageEntry/StageEntry.asmx?op=GetStageList","")

End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Thanks for reply...

I have tried below code but its showing as error.Please help to solve this issues

** Activity (productionentry) Create (first time) **
** Activity (productionentry) Resume **
ResponseError. Reason: Internal Server Error, Response: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. ---&gt; System.Xml.XmlException: Root element is missing.

at System.Xml.XmlTextReaderImpl.Throw(Exception e)

at System.Xml.XmlTextReaderImpl.ParseDocumentContent()

at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()

at System.Xml.XmlReader.MoveToContent()

at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()

at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()

at System.Web.Services.Protocols.SoapServerProtocol.Initialize()

at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing)

--- End of inner exception stack trace ---</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>
** Activity (productionentry) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **


Code : -
Code:
Public Sub WSCallSoapURL(URL As String, Parameters As String) As ResumableSub
    Dim Result As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString (URL, Parameters)
        j.GetRequest.SetHeader("Content-Type","text/xml")
        j.GetRequest.SetHeader("Content-length", Parameters.Length)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        Else
            ToastMessageShow("¡Hummm...!",False)
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return Result
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("ProductionEntry")
    WSCallSoapURL("http://103.76.188.138:85/StageEntry/StageEntry.asmx?op=GetStageList","")

End Sub
create the body by viewing the properties that the web service has
here
result:
1689218874540.png


Note:
I can post the code, but the idea is that you understand what you are developing.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Thanks for reply...

I would like to read data from GetStageList (Soap Request) and loaded in to combobox...
my darling

I have to know the results of the web service and what values it wants in the combobox.

You can post the valid values of:
<FSlNo>int</FSlNo>
<TSlNo>int</TSlNo>
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
oh .........
my darling

I have to know the results of the web service and what values it wants in the combobox.

You can post the valid values of:
<FSlNo>int</FSlNo>
<TSlNo>int</TSlNo>
sorry........
these two values are parameter
FSlNo = 10
TSlNo = 50
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
oh .........

sorry........
these two values are parameter
FSlNo = 10
TSlNo = 50
what data do you want
JSON:
{
    "soap:Envelope": {
        "Attributes": {
            "xmlns:xsd": "http:\/\/www.w3.org\/2001\/XMLSchema",
            "xmlns:soap": "http:\/\/schemas.xmlsoap.org\/soap\/envelope\/",
            "xmlns:xsi": "http:\/\/www.w3.org\/2001\/XMLSchema-instance"
        },
        "soap:Body": {
            "GetStageListResponse": {
                "Attributes": {
                    "xmlns": "http:\/\/tempuri.org\/"
                },
                "GetStageListResult": {
                    "xs:schema": {
                        "Attributes": {
                            "xmlns": "",
                            "xmlns:msdata": "urn:schemas-microsoft-com:xml-msdata",
                            "id": "NewDataSet",
                            "xmlns:xs": "http:\/\/www.w3.org\/2001\/XMLSchema"
                        },
                        "xs:element": {
                            "xs:complexType": {
                                "xs:choice": {
                                    "Attributes": {
                                        "minOccurs": "0",
                                        "maxOccurs": "unbounded"
                                    },
                                    "xs:element": {
                                        "xs:complexType": {
                                            "xs:sequence": {
                                                "xs:element": [
                                                    {
                                                        "Attributes": {
                                                            "minOccurs": "0",
                                                            "name": "Serial",
                                                            "type": "xs:short"
                                                        },
                                                        "Text": ""
                                                    },
                                                    {
                                                        "Attributes": {
                                                            "minOccurs": "0",
                                                            "name": "Stage",
                                                            "type": "xs:string"
                                                        },
                                                        "Text": ""
                                                    }
                                                ]
                                            }
                                        },
                                        "Attributes": {
                                            "name": "Table"
                                        }
                                    }
                                }
                            },
                            "Attributes": {
                                "msdata:IsDataSet": "true",
                                "msdata:UseCurrentLocale": "true",
                                "name": "NewDataSet"
                            }
                        }
                    },
                    "diffgr:diffgram": {
                        "NewDataSet": {
                            "Table": [
                                {
                                    "Serial": "10",
                                    "Attributes": {
                                        "msdata:rowOrder": "0",
                                        "diffgr:id": "Table1"
                                    },
                                    "Stage": "Cutting In"
                                },
                                {
                                    "Serial": "20",
                                    "Attributes": {
                                        "msdata:rowOrder": "1",
                                        "diffgr:id": "Table2"
                                    },
                                    "Stage": "Cutting Out"
                                },
                                {
                                    "Serial": "30",
                                    "Attributes": {
                                        "msdata:rowOrder": "2",
                                        "diffgr:id": "Table3"
                                    },
                                    "Stage": "Marking Out"
                                },
                                {
                                    "Serial": "35",
                                    "Attributes": {
                                        "msdata:rowOrder": "3",
                                        "diffgr:id": "Table4"
                                    },
                                    "Stage": "Spray In"
                                },
                                {
                                    "Serial": "40",
                                    "Attributes": {
                                        "msdata:rowOrder": "4",
                                        "diffgr:id": "Table5"
                                    },
                                    "Stage": "Spray Out"
                                },
                                {
                                    "Serial": "45",
                                    "Attributes": {
                                        "msdata:rowOrder": "5",
                                        "diffgr:id": "Table6"
                                    },
                                    "Stage": "Slitting In"
                                },
                                {
                                    "Serial": "50",
                                    "Attributes": {
                                        "msdata:rowOrder": "6",
                                        "diffgr:id": "Table7"
                                    },
                                    "Stage": "Slitting Out"
                                }
                            ],
                            "Attributes": {
                                "xmlns": ""
                            }
                        },
                        "Attributes": {
                            "xmlns:msdata": "urn:schemas-microsoft-com:xml-msdata",
                            "xmlns:diffgr": "urn:schemas-microsoft-com:xml-diffgram-v1"
                        }
                    }
                }
            }
        }
    }
}
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
what data do you want
JSON:
{
    "soap:Envelope": {
        "Attributes": {
            "xmlns:xsd": "http:\/\/www.w3.org\/2001\/XMLSchema",
            "xmlns:soap": "http:\/\/schemas.xmlsoap.org\/soap\/envelope\/",
            "xmlns:xsi": "http:\/\/www.w3.org\/2001\/XMLSchema-instance"
        },
        "soap:Body": {
            "GetStageListResponse": {
                "Attributes": {
                    "xmlns": "http:\/\/tempuri.org\/"
                },
                "GetStageListResult": {
                    "xs:schema": {
                        "Attributes": {
                            "xmlns": "",
                            "xmlns:msdata": "urn:schemas-microsoft-com:xml-msdata",
                            "id": "NewDataSet",
                            "xmlns:xs": "http:\/\/www.w3.org\/2001\/XMLSchema"
                        },
                        "xs:element": {
                            "xs:complexType": {
                                "xs:choice": {
                                    "Attributes": {
                                        "minOccurs": "0",
                                        "maxOccurs": "unbounded"
                                    },
                                    "xs:element": {
                                        "xs:complexType": {
                                            "xs:sequence": {
                                                "xs:element": [
                                                    {
                                                        "Attributes": {
                                                            "minOccurs": "0",
                                                            "name": "Serial",
                                                            "type": "xs:short"
                                                        },
                                                        "Text": ""
                                                    },
                                                    {
                                                        "Attributes": {
                                                            "minOccurs": "0",
                                                            "name": "Stage",
                                                            "type": "xs:string"
                                                        },
                                                        "Text": ""
                                                    }
                                                ]
                                            }
                                        },
                                        "Attributes": {
                                            "name": "Table"
                                        }
                                    }
                                }
                            },
                            "Attributes": {
                                "msdata:IsDataSet": "true",
                                "msdata:UseCurrentLocale": "true",
                                "name": "NewDataSet"
                            }
                        }
                    },
                    "diffgr:diffgram": {
                        "NewDataSet": {
                            "Table": [
                                {
                                    "Serial": "10",
                                    "Attributes": {
                                        "msdata:rowOrder": "0",
                                        "diffgr:id": "Table1"
                                    },
                                    "Stage": "Cutting In"
                                },
                                {
                                    "Serial": "20",
                                    "Attributes": {
                                        "msdata:rowOrder": "1",
                                        "diffgr:id": "Table2"
                                    },
                                    "Stage": "Cutting Out"
                                },
                                {
                                    "Serial": "30",
                                    "Attributes": {
                                        "msdata:rowOrder": "2",
                                        "diffgr:id": "Table3"
                                    },
                                    "Stage": "Marking Out"
                                },
                                {
                                    "Serial": "35",
                                    "Attributes": {
                                        "msdata:rowOrder": "3",
                                        "diffgr:id": "Table4"
                                    },
                                    "Stage": "Spray In"
                                },
                                {
                                    "Serial": "40",
                                    "Attributes": {
                                        "msdata:rowOrder": "4",
                                        "diffgr:id": "Table5"
                                    },
                                    "Stage": "Spray Out"
                                },
                                {
                                    "Serial": "45",
                                    "Attributes": {
                                        "msdata:rowOrder": "5",
                                        "diffgr:id": "Table6"
                                    },
                                    "Stage": "Slitting In"
                                },
                                {
                                    "Serial": "50",
                                    "Attributes": {
                                        "msdata:rowOrder": "6",
                                        "diffgr:id": "Table7"
                                    },
                                    "Stage": "Slitting Out"
                                }
                            ],
                            "Attributes": {
                                "xmlns": ""
                            }
                        },
                        "Attributes": {
                            "xmlns:msdata": "urn:schemas-microsoft-com:xml-msdata",
                            "xmlns:diffgr": "urn:schemas-microsoft-com:xml-diffgram-v1"
                        }
                    }
                }
            }
        }
    }
}
Thanks for reply...
Please check my below requirement

Need Dataset:
"NewDataSet": {

                            "Table": [

                                {

                                    "Serial": "10",

                                    "Attributes": {

                                        "msdata:rowOrder": "0",

                                        "diffgr:id": "Table1"

                                    },

                                    "Stage": "Cutting In"

                                },

                                {

                                    "Serial": "20",

                                    "Attributes": {

                                        "msdata:rowOrder": "1",

                                        "diffgr:id": "Table2"

                                    },

                                    "Stage": "Cutting Out"

                                },

                                {

                                    "Serial": "30",

                                    "Attributes": {

                                        "msdata:rowOrder": "2",

                                        "diffgr:id": "Table3"

                                    },

                                    "Stage": "Marking Out"

                                },

                                {

                                    "Serial": "35",

                                    "Attributes": {

                                        "msdata:rowOrder": "3",

                                        "diffgr:id": "Table4"

                                    },

                                    "Stage": "Spray In"

                                },

                                {

                                    "Serial": "40",

                                    "Attributes": {

                                        "msdata:rowOrder": "4",

                                        "diffgr:id": "Table5"

                                    },

                                    "Stage": "Spray Out"

                                },

                                {

                                    "Serial": "45",

                                    "Attributes": {

                                        "msdata:rowOrder": "5",

                                        "diffgr:id": "Table6"

                                    },

                                    "Stage": "Slitting In"

                                },

                                {

                                    "Serial": "50",

                                    "Attributes": {

                                        "msdata:rowOrder": "6",

                                        "diffgr:id": "Table7"

                                    },

                                    "Stage": "Slitting Out"

                                }

                            ],
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Thanks for reply...
Please check my below requirement

Need Dataset:
"NewDataSet": {

                            "Table": [

                                {

                                    "Serial": "10",

                                    "Attributes": {

                                        "msdata:rowOrder": "0",

                                        "diffgr:id": "Table1"

                                    },

                                    "Stage": "Cutting In"

                                },

                                {

                                    "Serial": "20",

                                    "Attributes": {

                                        "msdata:rowOrder": "1",

                                        "diffgr:id": "Table2"

                                    },

                                    "Stage": "Cutting Out"

                                },

                                {

                                    "Serial": "30",

                                    "Attributes": {

                                        "msdata:rowOrder": "2",

                                        "diffgr:id": "Table3"

                                    },

                                    "Stage": "Marking Out"

                                },

                                {

                                    "Serial": "35",

                                    "Attributes": {

                                        "msdata:rowOrder": "3",

                                        "diffgr:id": "Table4"

                                    },

                                    "Stage": "Spray In"

                                },

                                {

                                    "Serial": "40",

                                    "Attributes": {

                                        "msdata:rowOrder": "4",

                                        "diffgr:id": "Table5"

                                    },

                                    "Stage": "Spray Out"

                                },

                                {

                                    "Serial": "45",

                                    "Attributes": {

                                        "msdata:rowOrder": "5",

                                        "diffgr:id": "Table6"

                                    },

                                    "Stage": "Slitting In"

                                },

                                {

                                    "Serial": "50",

                                    "Attributes": {

                                        "msdata:rowOrder": "6",

                                        "diffgr:id": "Table7"

                                    },

                                    "Stage": "Slitting Out"

                                }

                            ],
please help
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
This is the result of the response data you want.
Now you can fill the combobox
Attached B4X demo file
1689278747870.png

B4X:
Public Sub TestSoapURL(FSlNo As Int, TSlNo As Int)
    Dim XMLLink As String = "http://103.76.188.138:85/StageEntry/StageEntry.asmx?op=GetStageList"

    Dim XMLBody As XMLBuilder
    XMLBody = XMLBody.create("soap:Envelope")
    XMLBody = XMLBody.attribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
    XMLBody = XMLBody.attribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema")
    XMLBody = XMLBody.attribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/")
    XMLBody = XMLBody.element("soap:Body")
    XMLBody = XMLBody.element2("GetStageList","http://tempuri.org/")
    XMLBody = XMLBody.element("FSlNo").text(FSlNo).up
    XMLBody = XMLBody.element("TSlNo").text(TSlNo).up
    Dim XMLBodyRequest As String = XMLBody.asString2(CreateMap("indent": "yes"))
'    Log(XMLBodyRequest)

    Dim XMLSoapAction As String = "http://tempuri.org/GetStageList"
    
    Wait For(WSCallSoapURL(XMLLink, XMLBodyRequest, XMLSoapAction)) Complete (XMLResult As String)
    If XMLResult.Length = 0 Then Return

'    Log("--- Result XML to Json ---")
    Dim Xml2Map1 As Xml2Map
    Xml2Map1.Initialize
    Dim mRoot As Map = Xml2Map1.Parse(XMLResult)
    Dim Body As Map = mRoot.Get("soap:Envelope").As(Map).Get("soap:Body")
    Dim GetStageListResponse As Map = Body.Get("GetStageListResponse")
    Dim GetStageListResult As Map = GetStageListResponse.Get("GetStageListResult")
    Dim Diffgram As Map = GetStageListResult.Get("diffgr:diffgram")
    Dim NewDataSet As Map = Diffgram.Get("NewDataSet")
    Dim Table As List = NewDataSet.Get("Table")
    For Each colTable As Map In Table
        Dim Serial As String = colTable.Get("Serial")
        Dim rowOrder As String = colTable.Get("Attributes").As(Map).Get("msdata:rowOrder")
        Dim id As String = colTable.Get("Attributes").As(Map).Get("diffgr:id")
        Dim Stage As String = colTable.Get("Stage")
        Log($"${id} | ${Serial} | ${rowOrder} | ${Stage}"$)
    Next
End Sub

Public Sub WSCallSoapURL(URL As String, Parameters As String, SoapAction As String) As ResumableSub
    Dim Result As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString (URL, Parameters)
        j.GetRequest.SetHeader("Content-length", Parameters.Length)
        j.GetRequest.SetContentType("text/xml; charset=utf-8")
        j.GetRequest.SetHeader("SOAPAction", SoapAction)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        Else
            Log(j.ErrorMessage)
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return Result
End Sub
 

Attachments

  • SOAP-Asmx.zip
    14.7 KB · Views: 150
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
This is the result of the response data you want.
Now you can fill the combobox
Attached B4X demo file
View attachment 143696
B4X:
Public Sub TestSoapURL(FSlNo As Int, TSlNo As Int)
    Dim XMLLink As String = "http://103.76.188.138:85/StageEntry/StageEntry.asmx?op=GetStageList"

    Dim XMLBody As XMLBuilder
    XMLBody = XMLBody.create("soap:Envelope")
    XMLBody = XMLBody.attribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
    XMLBody = XMLBody.attribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema")
    XMLBody = XMLBody.attribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/")
    XMLBody = XMLBody.element("soap:Body")
    XMLBody = XMLBody.element2("GetStageList","http://tempuri.org/")
    XMLBody = XMLBody.element("FSlNo").text(FSlNo).up
    XMLBody = XMLBody.element("TSlNo").text(TSlNo).up
    Dim XMLBodyRequest As String = XMLBody.asString2(CreateMap("indent": "yes"))
'    Log(XMLBodyRequest)

    Dim XMLSoapAction As String = "http://tempuri.org/GetStageList"
   
    Wait For(WSCallSoapURL(XMLLink, XMLBodyRequest, XMLSoapAction)) Complete (XMLResult As String)
    If XMLResult.Length = 0 Then Return

'    Log("--- Result XML to Json ---")
    Dim Xml2Map1 As Xml2Map
    Xml2Map1.Initialize
    Dim mRoot As Map = Xml2Map1.Parse(XMLResult)
    Dim Body As Map = mRoot.Get("soap:Envelope").As(Map).Get("soap:Body")
    Dim GetStageListResponse As Map = Body.Get("GetStageListResponse")
    Dim GetStageListResult As Map = GetStageListResponse.Get("GetStageListResult")
    Dim Diffgram As Map = GetStageListResult.Get("diffgr:diffgram")
    Dim NewDataSet As Map = Diffgram.Get("NewDataSet")
    Dim Table As List = NewDataSet.Get("Table")
    For Each colTable As Map In Table
        Dim Serial As String = colTable.Get("Serial")
        Dim rowOrder As String = colTable.Get("Attributes").As(Map).Get("msdata:rowOrder")
        Dim id As String = colTable.Get("Attributes").As(Map).Get("diffgr:id")
        Dim Stage As String = colTable.Get("Stage")
        Log($"${id} | ${Serial} | ${rowOrder} | ${Stage}"$)
    Next
End Sub

Public Sub WSCallSoapURL(URL As String, Parameters As String, SoapAction As String) As ResumableSub
    Dim Result As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString (URL, Parameters)
        j.GetRequest.SetHeader("Content-length", Parameters.Length)
        j.GetRequest.SetContentType("text/xml; charset=utf-8")
        j.GetRequest.SetHeader("SOAPAction", SoapAction)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        Else
            Log(j.ErrorMessage)
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return Result
End Sub
Thanks
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
This is the result of the response data you want.
Now you can fill the combobox
Attached B4X demo file
View attachment 143696
B4X:
Public Sub TestSoapURL(FSlNo As Int, TSlNo As Int)
    Dim XMLLink As String = "http://103.76.188.138:85/StageEntry/StageEntry.asmx?op=GetStageList"

    Dim XMLBody As XMLBuilder
    XMLBody = XMLBody.create("soap:Envelope")
    XMLBody = XMLBody.attribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
    XMLBody = XMLBody.attribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema")
    XMLBody = XMLBody.attribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/")
    XMLBody = XMLBody.element("soap:Body")
    XMLBody = XMLBody.element2("GetStageList","http://tempuri.org/")
    XMLBody = XMLBody.element("FSlNo").text(FSlNo).up
    XMLBody = XMLBody.element("TSlNo").text(TSlNo).up
    Dim XMLBodyRequest As String = XMLBody.asString2(CreateMap("indent": "yes"))
'    Log(XMLBodyRequest)

    Dim XMLSoapAction As String = "http://tempuri.org/GetStageList"
   
    Wait For(WSCallSoapURL(XMLLink, XMLBodyRequest, XMLSoapAction)) Complete (XMLResult As String)
    If XMLResult.Length = 0 Then Return

'    Log("--- Result XML to Json ---")
    Dim Xml2Map1 As Xml2Map
    Xml2Map1.Initialize
    Dim mRoot As Map = Xml2Map1.Parse(XMLResult)
    Dim Body As Map = mRoot.Get("soap:Envelope").As(Map).Get("soap:Body")
    Dim GetStageListResponse As Map = Body.Get("GetStageListResponse")
    Dim GetStageListResult As Map = GetStageListResponse.Get("GetStageListResult")
    Dim Diffgram As Map = GetStageListResult.Get("diffgr:diffgram")
    Dim NewDataSet As Map = Diffgram.Get("NewDataSet")
    Dim Table As List = NewDataSet.Get("Table")
    For Each colTable As Map In Table
        Dim Serial As String = colTable.Get("Serial")
        Dim rowOrder As String = colTable.Get("Attributes").As(Map).Get("msdata:rowOrder")
        Dim id As String = colTable.Get("Attributes").As(Map).Get("diffgr:id")
        Dim Stage As String = colTable.Get("Stage")
        Log($"${id} | ${Serial} | ${rowOrder} | ${Stage}"$)
    Next
End Sub

Public Sub WSCallSoapURL(URL As String, Parameters As String, SoapAction As String) As ResumableSub
    Dim Result As String
    Dim j As HttpJob
    Try
        j.Initialize("", Me)
        j.PostString (URL, Parameters)
        j.GetRequest.SetHeader("Content-length", Parameters.Length)
        j.GetRequest.SetContentType("text/xml; charset=utf-8")
        j.GetRequest.SetHeader("SOAPAction", SoapAction)
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Result = j.GetString
        Else
            Log(j.ErrorMessage)
        End If
    Catch
        Log(LastException)
    End Try
    j.Release
    Return Result
End Sub
sorry for late reply....

I am getting below error message when I run above sample project.Please help to resolve this issues...
Error:
*** Receiver (httputils2service) Receive (first time) ***
(Http client initialized with accept all option.)
Error occurred on line: 53 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:65)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8577)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
change:
B4X:
    Log("--- Result XML to Json ---")
    Dim Xml2Map1 As Xml2Map
    Xml2Map1.Initialize
    Dim mRoot As Map = Xml2Map1.Parse(XMLResult)
    Dim Body As Map = mRoot.Get("Envelope").As(Map).Get("Body")
    Dim GetStageListResponse As Map = Body.Get("GetStageListResponse")
    Dim GetStageListResult As Map = GetStageListResponse.Get("GetStageListResult")
    Dim Diffgram As Map = GetStageListResult.Get("diffgram")
    Dim NewDataSet As Map = Diffgram.Get("NewDataSet")
    Dim Table As List = NewDataSet.Get("Table")
    For Each colTable As Map In Table
        Dim Serial As String = colTable.Get("Serial")
        Dim rowOrder As String = colTable.Get("Attributes").As(Map).Get("rowOrder")
        Dim id As String = colTable.Get("Attributes").As(Map).Get("id")
        Dim Stage As String = colTable.Get("Stage")
        Log($"${id} | ${Serial} | ${rowOrder} | ${Stage}"$)
    Next
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Note:
XML2Map lib in B4J includes double dot tags and in B4A it doesn't.

I have corrected this class so that they are the same in both environments.

But I haven't asked @Erel to make the changes.

Sample:
B4J:
mRoot.Get("soap:Envelope").As(Map).Get("soap:Body")
B4A
mRoot.Get("Envelope").As(Map).Get("Body")
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Attached modified XML2MAP file
See comment oparra
 

Attachments

  • Xml2Map2.bas
    2.9 KB · Views: 153
Last edited:
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
Note:
XML2Map lib in B4J includes double dot tags and in B4A it doesn't.

I have corrected this class so that they are the same in both environments.

But I haven't asked @Erel to make the changes.

Sample:
B4J:

B4A
please check the below error messge after changing the above code...
Please help
Error in Dataset Element:
*** Receiver (httputils2service) Receive (first time) ***
(Http client initialized with accept all option.)
Error occurred on line: 60 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:65)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8577)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
 

Attachments

  • SOAP-Asmx.zip
    11.8 KB · Views: 135
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Dim Xml2Map1 As Xml2Map
Xml2Map1.Initialize
Dim mRoot As Map = Xml2Map1.Parse(XMLResult)
Dim Body As Map = mRoot.Get("Envelope").As(Map).Get("Body")
Dim GetStageListResponse As Map = Body.Get("GetStageListResponse")
Dim GetStageListResult As Map = GetStageListResponse.Get("GetStageListResult")
Dim Diffgram As Map = GetStageListResult.Get("diffgr:diffgram")
Dim NewDataSet As Map = Diffgram.Get("NewDataSet")
Dim Table As List = NewDataSet.Get("Table")
For Each colTable As Map In Table
Dim Serial As String = colTable.Get("Serial")
Dim rowOrder As String = colTable.Get("Attributes").As(Map).Get("msdata:rowOrder")
Dim id As String = colTable.Get("Attributes").As(Map).Get("diffgr:id")

Dim Stage As String = colTable.Get("Stage")
Log($"${id} | ${Serial} | ${rowOrder} | ${Stage}"$)
Next
B4X:
    Dim Body As Map = mRoot.Get("Envelope").As(Map).Get("Body")
    Dim GetStageListResponse As Map = Body.Get("GetStageListResponse")
    Dim GetStageListResult As Map = GetStageListResponse.Get("GetStageListResult")
    Dim Diffgram As Map = GetStageListResult.Get("diffgram")
    Dim NewDataSet As Map = Diffgram.Get("NewDataSet")
    Dim Table As List = NewDataSet.Get("Table")
    For Each colTable As Map In Table
        Dim Serial As String = colTable.Get("Serial")
        Dim rowOrder As String = colTable.Get("Attributes").As(Map).Get("rowOrder")
        Dim id As String = colTable.Get("Attributes").As(Map).Get("id")
        Dim Stage As String = colTable.Get("Stage")
        Log($"${id} | ${Serial} | ${rowOrder} | ${Stage}"$)
    Next
1689392641494.png
 
Last edited:
Upvote 0
Top