Does B4A Do SOAP?

TestMyChess

Member
Licensed User
Longtime User
Hi,

This is (almost?) the final piece of the jigsaw that I'd like to get sorted before I get stuck into my app. Chess endgames with 5 and 6 pieces are fully calculated and stored in large databases. The 5-piece ones are online at Tablebase WebService - Lokasoft - Home of ChessPartner. This page has the following VB code to access the database using the MSSOAP toolkit.
B4X:
Dim Client As SoapClient
Dim Result As String
Set Client = New SoapClient
Client.mssoapinit "http://www.lokasoft.nl/tbweb/tbapi.wsdl"
Result = SoapClient.ProbePosition("6k1/6p1/8/8/8/8/4P2P/6K1 w - -")

What is the B4A equivalent to this code? I've tried looking at httpUtils2 but I'm not getting very far.

Thanks in advance.

John Harbour
Bedford, UK
 

TestMyChess

Member
Licensed User
Longtime User
OK. Can't say I know where to start with "manually build the XML request" but I'll see what I can do.

I understand that there is a SOAP client in the Java API. Would it be difficult to create a B4A library that was a wrapper to this?

John Harbour
Bedford, UK
 
Upvote 0

TestMyChess

Member
Licensed User
Longtime User
I found Wireshark and so got this XML
B4X:
<?xml
   version="1.0"
   encoding="UTF-8"
   standalone="no"
?>
<SOAP-ENV:Envelope
   xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema"
   xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/"
   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <SOAPSDK4:GetBestMoves
         xmlns:SOAPSDK4="http://lokasoft.org/message/">
         <fen>
         6k1/8/2Q3K1/8/8/8/8/8 w
         </fen>
      </SOAPSDK4:GetBestMoves>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I then hacked the HttpUtils2 example as follows
B4X:
job2.PostString("http://www.lokasoft.nl/tbweb/tbapi.asp", _
   "<?xml version=""1.0""...</SOAP-ENV:Envelope>")
This gives
B4X:
<h2>500 - Internal server error.</h2>
<h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3>
so maybe the XML isn't quite right or I need to set up the HTTP headers (correct jargon?) in some way. I feel I'm close here. I'm feeling a bit guilty wasting Erel's valuable time on my beginner-level hacking, but I'd very much like to get this working.

Thanks as always.

John Harbour
Bedford, UK
 
Upvote 0

TestMyChess

Member
Licensed User
Longtime User
OK. I've now got
B4X:
   job2.PostString("http://www.lokasoft.nl/tbweb/tbapi.asp", _
   File.ReadString(File.DirAssets, "GetBestMoves.xml"))
and I've changed your code in the HttpJob module to
B4X:
Public Sub PostBytes(Link As String, Data() As Byte)
   mLink = Link
   req.InitializePost2(Link, Data)
   req.SetContentType("text/xml; charset=""UTF-8""") 'JH added
   CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub
I wasn't sure where to put this SetContentType() call, but this seemed to be the obvious place.

Neither change made any difference - still exactly the same error message.

John Harbour
Bedford, UK
 
Upvote 0

TestMyChess

Member
Licensed User
Longtime User
Sorted!

Stupidity on my part - I had left some spurious text in the GetBestMoves.xml file. Thanks very much for your help and patience.

John Harbour
Bedford, UK
 
Upvote 0

mariusturnkey

Member
Licensed User
Longtime User
Hi John,

I will soon have to embark on a similar mission as what you already seemed to have overcome.

Did you take the communication with a SOAP Web Server to completion? In other words were you able to send requests and receive and interpret responses received from the web service in XML packets.

Did you have have to build your your own SAX or other XML interpreter on the A4B side?

Could you share some of your experiences?

Regards
Marius
 
Upvote 0

mariusturnkey

Member
Licensed User
Longtime User
Perfect Errol,

Ill give it a bash, I saw lots of messages re SOAP and Web Services.

I think what I might do is to try and create a bit of a tutorial once I have managed to get it right, which I can then contribute back to the community. As a database applications developer, the ability to communicate with SOAP Web Service is most probably one of the most important "features" to me.
 
Upvote 0

TestMyChess

Member
Licensed User
Longtime User

I build this XML string

B4X:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAPSDK4:GetBestMoves xmlns:SOAPSDK4="http://lokasoft.org/message/">
<fen>4k3/8/8/8/8/8/4P3/4K3 w</fen>
</SOAPSDK4:GetBestMoves>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

where the only variable is the "4k3/8/8/8/8/8/4P3/4K3 w" which represents a chess position in FEN notation. Then

B4X:
Dim job As HttpJob
Dim XML As String = "<?xml ... :Envelope>"

job.Initialize("Job", Me)
job.PostString("http://www.lokasoft.nl/tbweb/tbapi.asp", XML)
job.GetRequest.SetContentType("text/xml; charset=""UTF-8""")

Then

B4X:
Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        strResult = Job.GetString

strResult contains the list of moves from the passed position. I ignore the fact that these are wrapped up as XML and simply parse out the information I want using a regular expression. Not really what you could call "writing my own XML interpreter", so I can't help you with that bit.

Hope this helps.

John
 
Upvote 0

mariusturnkey

Member
Licensed User
Longtime User
Thanks replying John.

Once I have implemented I will most definitely post something back to this Forum for the benefit of other members.

Regards
Marius
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…