Android Question How -> WebService (asmx) - GetDataSet

jaraiza

Active Member
Licensed User
Longtime User
Hi,

I've a WebService (something like http://www.domain.com/CellWS.asmx)

I've finally done the basic functionality in SOAP1.2, I'm able to read the resulting data in this format:

B4X:
<?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>
    <LoginResponse xmlns="http://tempuri.org/">
      <LoginResult>
        <Result01>string</Result01>
        <Result02>string</Result02>
        <Result03>string</Result03>
        <Result04>string</Result04>
      </LoginResult>
    </LoginResponse>
  </soap12:Body>
</soap12:Envelope>

Now I'm facing a new problem, there's one WebService that returns a Table Dataset, and the result data is this:
B4X:
<?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>
    <GetDataSetResponse xmlns="http://tempuri.org/">
      <GetDataSetResult>
        <xsd:schema>schema</xsd:schema>xml</GetDataSetResult>
    </GetDataSetResponse>
  </soap12:Body>
</soap12:Envelope>

Inside VisualStudio the WebService returns a dataset with four columns and many rows.

Can you help me understanding how to read that result?

Thanks a lot!
 

jaraiza

Active Member
Licensed User
Longtime User
I tried before posting, but I'm getting errors so I don't know what I'm doing wrong.

First Step:
B4X:
Sub Globals
    Dim xmlParser As SaxParser
End Sub

Sub wsGetDataSet (wsQuery As String)
    'XML = WebService Data
    job1.Initialize("JOBSOAP_getTransact", Me)
    job1.PostString ("http://www.domain.com/CellWS.asmx)", XML)
    job1.GetRequest.SetContentType("application/soap+xml")
End Sub
Second Step:
B4X:
Sub JobDone (Job As HttpJob)
    If Job.Success Then
        Dim Res As String
        Dim ResIS As InputStream

        Res = Job.GetString
        ResIS = Job.GetInputStream

           Select Job.JobName
               Case "JOBSOAP_getTransact"
                    Dim wsTable As String = CommonFuncs.xmlGetTagContent(Res,"GetDataSetResult")
                    xmlParser.Parse(ResIS,"xmlParserSub")
           End Select
   End If
End Sub

Sub xmlParserSub_EndElement (Uri As String, Name As String, Text As StringBuilder)
End Sub

Variable "wsTable" is there to debug response, I can see the headers and the values in the string (the log truncates above 4000 chars, but I can see enough data)

The error is thrown at xmlParser.Parse line:
B4X:
Error occurred on line: 122 (reptransact)
java.lang.NullPointerException

DEBUG:
ResIS.BytesAvailable returns "6261 (0x1875)"

ResIS -> buf -> 0..999 returns "0 (0x0)"
ResIS -> count returns "0 (0x0)"

Also, the rapid debugger breaks at that line, I need to use legacy debugger to be able to see the "NullPointerException" error.

Any idea what's happening?

Thanks!
 
Upvote 0

Reviewnow

Active Member
Licensed User
Longtime User
This should get you going..
Mistakes Made.
the inputstream was never closed
the job was never released


B4X:
Sub JobDone (Job As HttpJob)
    If Job.Success Then
       

         Select Job.JobName
         Case "JOBSOAP_getTransact"
        Dim Res As String
        Dim ResIS As InputStream
        Res = Job.GetString
        ResIS = Job.GetInputStream
       
Dim wsTable As String = CommonFuncs.xmlGetTagContent(Res,"GetDataSetResult")
                    xmlParser.Parse(ResIS,"xmlParserSub")
ResIS.Close 'Close the inputstream
                   
            
           End Select

   End If
Job.Release ' Release the job
End Sub


Sub xmlParserSub_EndElement (Uri AsString, Name As String, Text As StringBuilder)
If xmlParser.Parents.IndexOf("GetDataSetResult") > -1 Then
  'do your additional parsing here..


end if

End Sub
 
Last edited:
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
This should get you going..
Mistakes Made.
the inputstream was never closed
the job was never released
In my code I have job release. I didn't have close stream, but it can't be the problem because as I've said, the error is in "
xmlParser.Parse" line, so it's before any kind of "closure".
 
Upvote 0

jaraiza

Active Member
Licensed User
Longtime User
Hi Erel,

Here's the info:

==============================================================
java.lang.NullPointerException
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:78)
at anywheresoftware.b4a.objects.SaxParser.Parse(SaxParser.java:73)
at b4a.example.reptransact._jobdone(reptransact.java:549)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:952)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
==============================================================

Thanks!
 
Upvote 0
Top