B4J Question Using WebServices - Case Solved - With Example

virpalacios

Active Member
Licensed User
Longtime User
Solved

This is an example how to call a public web service in order to add two numbers, key parts are: The Envelop, The end point and the Content Type, I figure out the content type reading outputs using SOAPUI.

Thanks very much for all of your help with my previous issues.

Best Regards

Virgilio


The end point
http://www.dneonline.com/calculator.asmx

The envelop (saved as request.xml in DirAssest - it add two numbers 6 and 5)

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:Add>
<tem:intA>6</tem:intA>
<tem:intB>5</tem:intB>
</tem:Add>
</soapenv:Body>
</soapenv:Envelope>

B4J Code

B4J Code:
Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Dim job As HttpJob
    job.Initialize("Job", Me)
    Dim msg As String = File.ReadString(File.DirAssets, "request.xml")
    Log(msg)
    job.PostString("http://www.dneonline.com/calculator.asmx", msg)
    job.GetRequest.SetContentType("text/xml")
    StartMessageLoop
End Sub
Public Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        Log("Webservice Correct Correct")
        Log(Job.GetString)
    Else
        Log("Error Webservice")
        Log(Job.ErrorMessage)
    End If
    Job.Release
    ExitApplication2(0)
End Sub


Best Regards Virgilio
 
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Hi
You cant call wait for in the app start sub. Wrap your function in another sub and call it from the appstart

Then before the end sub of apostaré and after the new sub write

Startmessageloop
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
Set the header SoapAction (with the quotation marks). Also set correctly the content type. If you click on the .asmx link you posted and then on add you can get these values.
 
Last edited:
Upvote 0
Top