Some success with accessing Web Service via SOAP

SteveBee

Member
Licensed User
Longtime User
I've posted some problem I was having around this, so I thought I'd now post the insights and work-arounds that I've come to.

The WS method I was using for test was producing too many items, and I could not properly inspect the full returned string (because Log truncates, and I can't copy a variable in the debugger), so I put up a 'test' web service.

When I use an ASP.NET (proxy) as client, I get a nice clean return:

<Stores><Record><StoreName>Albany Creek</StoreName><Address>Shop 19, Albany Market Place,720 Albany Creek Road,Albany Creek QLD 4035</Address><Phone1>07 xxxx4334</Phone1><Phone2>SS - xxxx 661 140</Phone2><Fax>07 xxxx4313</Fax><Email>[email protected]</Email><StoreSysID>89</StoreSysID><Latitude>-27.345486</Latitude><Longitude>152.966995</Longitude></Record><Record><StoreName>Albury</StoreName><Address>Shop 3, 659 Young Street,Albury,NSW 2640</Address><Phone1>02 xxx2111</Phone1><Phone2></Phone2><Fax>02 xxxx32112</Fax><Email>[email protected]</Email><StoreSysID>117</StoreSysID><Latitude>-36.071899</Latitude><Longitude>146.925766</Longitude></Record><Record><StoreName>Altona</StoreName><Address>114 Millers Road,Altona,VIC 3025</Address><Phone1>03 xxxx522</Phone1><Phone2></Phone2><Fax>03 93144566</Fax><Email>[email protected]</Email><StoreSysID>120</StoreSysID><Latitude>-37.826740</Latitude><Longitude>144.848648</Longitude></Record></Stores>



But B4a has *no* in-built way of handling SOAP, so the return I get from it is this (below):

<?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><StoresListing_TESTResponse xmlns="http://cheesecake.com.au/"><StoresListing_TESTResult>&lt;Stores&gt;&lt;Record&gt;&lt;StoreName&gt;Albany Creek&lt;/StoreName&gt;&lt;Address&gt;Shop 19, Albany Market Place,720 Albany Creek Road,Albany Creek QLD 4035&lt;/Address&gt;&lt;Phone1&gt;07 xxxx4334&lt;/Phone1&gt;&lt;Phone2&gt;SS - xxx1 140&lt;/Phone2&gt;&lt;Fax&gt;07 xxx313&lt;/Fax&gt;&lt;Email&gt;[email protected]&lt;/Email&gt;&lt;StoreSysID&gt;89&lt;/StoreSysID&gt;&lt;Latitude&gt;-27.345486&lt;/Latitude&gt;&lt;Longitude&gt;152.966995&lt;/Longitude&gt;&lt;/Record&gt;&lt;Record&gt;&lt;StoreName&gt;Albury&lt;/StoreName&gt;&lt;Address&gt;Shop 3, 659 Young Street,Albury,NSW 2640&lt;/Address&gt;&lt;Phone1&gt;02 xxxx111&lt;/Phone1&gt;&lt;Phone2&gt;&lt;/Phone2&gt;&lt;Fax&gt;02 xxxx32112&lt;/Fax&gt;&lt;Email&gt;[email protected]&lt;/Email&gt;&lt;StoreSysID&gt;117&lt;/StoreSysID&gt;&lt;Latitude&gt;-36.071899&lt;/Latitude&gt;&lt;Longitude&gt;146.925766&lt;/Longitude&gt;&lt;/Record&gt;&lt;Record&gt;&lt;StoreName&gt;Altona&lt;/StoreName&gt;&lt;Address&gt;114 Millers Road,Altona,VIC 3025&lt;/Address&gt;&lt;Phone1&gt;03 xxxx22&lt;/Phone1&gt;&lt;Phone2&gt;&lt;/Phone2&gt;&lt;Fax&gt;03 xxxx566&lt;/Fax&gt;&lt;Email&gt;[email protected]&lt;/Email&gt;&lt;StoreSysID&gt;120&lt;/StoreSysID&gt;&lt;Latitude&gt;-37.826740&lt;/Latitude&gt;&lt;Longitude&gt;144.848648&lt;/Longitude&gt;&lt;/Record&gt;&lt;/Stores&gt;</StoresListing_TESTResult></StoresListing_TESTResponse></soap:Body></soap:Envelope>



So it occurred to me to just string-slice out the part that I need, replace 'encoded' characters, and present that as XML to the parser.

B4X:
Sub JobDone (Job As String)
   Dim s1 As String, s2 As InputStream, p1 As Int, p2 As Int, xmlname As String
   If HttpUtils.IsSuccess(WS_url) Then
      s1 = HttpUtils.GetString(WS_url)
      s1 = s1.Replace("&lt;", "<").Replace("&gt;", ">")
      p1 = s1.IndexOf("<Stores>")
       p2 = s1.IndexOf("</Stores>")
       s1 = s1.SubString2(p1, p2 +9)
      xmlname = "ws_resp.xml"
      File.WriteString(File.DirInternalCache, xmlname, s1)

      s2 = File.OpenInput(File.DirInternalCache, xmlname)

      parser.Parse(s2, "Parser")
   End If
End Sub


Works like a charm!
Perhaps this may help someone else.. also happy to hear of any better ways to achieve the outcome

Steve
 

SteveBee

Member
Licensed User
Longtime User
BTW Geordie - here's an example (attached) of what you see once you put the URL in a browser. It defines the SOAP and variable structure for the WS.

Good luck.
 

Attachments

  • Clipboard01.jpg
    Clipboard01.jpg
    11.7 KB · Views: 281
  • Clipboard02.jpg
    Clipboard02.jpg
    48.8 KB · Views: 312
Upvote 0

GeordieJenner

Member
Licensed User
Longtime User
i actually got much further from your last note, thank you
this is the direction i was going. now all i have to do is figure out what the xml is being sent out by my client. i was able to get confirmation from the android that the service was being hit, just not sure what the xml is to hit one of the contracts in the service

thanks!
 
Upvote 0

GeordieJenner

Member
Licensed User
Longtime User
no, i mean the xml to talk to my services running on my server. the parameters are all in POCO classes, so i need to see how it convey's that. your code was a great help!
 
Upvote 0

aptinis7

Member
Licensed User
Longtime User
Web service responce

i have use this line of code

sxparser.Parse(XMLutils.GetWebServiceDataStream("return1", "http://10.0.2.2/myapp/WebService1.asmx?op=returnNextPage","action"), "sxparser")

i get error "java.lang.NullPointerException"

Do we have any idea whats wrong?


"return1" is my websrvice this is true?
what is action?


The function XMLutils.CallWebService works perfect!!
 
Upvote 0
Top