SOAP textbox info

sigster

Active Member
Licensed User
Hi

I am try to understand SOAP how do you work with this
if I am try to get GetCapitalByCountryResult to textbox

do you write the soap respond to xml file and then read it to the textbox
or do I need to get the string when I get the respond

I use this web service
http://www.ezzylearning.com/services/CountryInformationService.asmx?wsdl

this is what I get from the web service using SoapUI
B4X:
<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>
      <GetCapitalByCountryResponse xmlns="http://www.ezzylearning.com/services/CountryInformationService.asmx">
         <GetCapitalByCountryResult>Madrid</GetCapitalByCountryResult>
      </GetCapitalByCountryResponse>
   </soap:Body>
</soap:Envelope>

this is when I use basic4android
B4X:
<?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>
<GetCapitalByCountryResponse xmlns="http://www.ezzylearning.com/services/CountryInformationService.asmx">
<GetCapitalByCountryResult>Madrid</GetCapitalByCountryResult>
</GetCapitalByCountryResponse>
</soap:Body>
</soap:Envelope>
Regards
Sigster
 
Last edited:

sigster

Active Member
Licensed User
HI

Yes I was thinking about to extract the required values from the XML to textbox
was checking what is the best way to do this
so I will check out forum about XML library

will B4A have SOAP library in the future ?


Not sure that I understand the question. I guess that you will want to parse the response with the XML library and extract the required values from the XML.
Regards
Sigster
 

Jost aus Soest

Active Member
Licensed User
For such simple XML-parsing you could also use a sub like this (for well-formed XML-strings):
B4X:
Sub xmlGetTagContent(xml As String, tag As String) As String

   Dim i, j As Int

   'Find start-tag:
   i = xml.IndexOf("<" & tag & ">")
   If i < 0 Then i = xml.IndexOf("<" & tag & " ")
   If i < 0 Then Return Null
   i = xml.IndexOf2(">", i) + 1
   
   'Find stop-tag:
   j = xml.LastIndexOf("</" & tag & ">")
   If i < j Then
      Return xml.SubString2(i, j)
   Else
      Return Null
   End If

End Sub
So you can write xmlGetTagContent(xml, "GetCapitalByCountryResult") to get the requested result.
 

AbbasMohammed

Member
Licensed User
Inernel server error massage

Dears
i am trying to get the capital as follows but i am getting server internal error

my code is:


Sub Activity_Create(FirstTime As Boolean)
Dim job1 As HttpJob
Dim country As String
country="spain"
Dim str As String
str="<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>" & _
"<GetCapitalByCountryResponse xmlns='http://www.ezzylearning.com/services/CountryInformationService.asmx'>" & _
"<GetCapitalByCountryResult>" & country & "</GetCapitalByCountryResult>" & _
"</GetCapitalByCountryResponse>" & _
"</soap:Body>" & _
"</soap:Envelope>"
str=str.Replace("'",""")

job1.Initialize("Job1", Me)
job1.PostString("http://www.ezzylearning.com/services/CountryInformationService.asmx", str)

End Sub

Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then

Log(Job.GetString)
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
 

AbbasMohammed

Member
Licensed User
Error:internal server error

Dears,
i tried the following code also and the response is the same above.

Sub Activity_Create(FirstTime As Boolean)
Dim job1 As HttpJob
Dim country As String
country="spain"
Dim str As String
str="<?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>" & _
"<GetCapitalByCountryResponse xmlns='http://www.ezzylearning.com/services/CountryInformationService.asmx'>" & _
"<GetCapitalByCountryResult>" & country & "</GetCapitalByCountryResult>" & _
"</GetCapitalByCountryResponse>" & _
"</soap:Body>" & _
"</soap:Envelope>"
str=str.Replace("'",""")

job1.Initialize("Job1", Me)
job1.PostString("http://www.ezzylearning.com/services/CountryInformationService.asmx", str)

End Sub

Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then

Log(Job.GetString)
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
:BangHead::BangHead::BangHead:
 

AbbasMohammed

Member
Licensed User
:sign0013:
Dear Eerl
sorry to take so much of your time but i have follow your instruction and till now i get the same error
and the modified code is :

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim job1 As HttpJob
   Dim country As String
   country="spain"
   Dim str As String 
   str="<?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>" & _
      "<GetCapitalByCountryResponse xmlns='http://www.ezzylearning.com/services/CountryInformationService.asmx'>" & _
         "<GetCapitalByCountryResult>" & country & "</GetCapitalByCountryResult>" & _
      "</GetCapitalByCountryResponse>" & _
   "</soap:Body>" & _
"</soap:Envelope>"
  str=str.Replace("'", Chr(34))

   job1.Initialize("Job1", Me)
   job1.PostString("http://www.ezzylearning.com/services/CountryInformationService.asmx", str)
  job1.GetRequest.SetContentType("application/soap+xml")
   
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
   Log(Job.GetString)
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub
 

AbbasMohammed

Member
Licensed User
Dear Erel,
since yesterday i tried many times to solve this issue but for some reason i couldn't solve it, so if you have any advice i will be grateful.:signOops:
B.R
Abbas
 

Erel

Administrator
Staff member
Licensed User
This code works:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim j As HttpJob
   j.Initialize("j", Me)
   Dim msg As String = File.ReadString(File.DirAssets, "request.xml")
   msg = msg.Replace("$COUNTRYNAME$", "brazil")
   Log(msg)
   j.PostString("http://www.ezzylearning.com/services/CountryInformationService.asmx", _
      msg)
   j.GetRequest.SetContentType("application/soap+xml; charset=utf-8")
End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      Log(Job.GetString)
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub
You should create a file with the following text and add it to the Files tab:

<?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>
<GetCapitalByCountry xmlns="http://www.ezzylearning.com/services/CountryInformationService.asmx">
<countryName>$COUNTRYNAME$</countryName>
</GetCapitalByCountry>
</soap12:Body>
</soap12:Envelope>
 

AbbasMohammed

Member
Licensed User
Many thanks

:sign0098:
Dear Erel,
Many thanks for your kind support,i am very glad that i chose basic 4 android (100% for b4a + 1000% for your support).
B.R
Abbas
 

JakeBullet70

Well-Known Member
Licensed User
Running into a strange problem while trying to use this code...
It might be that I am on the current version 2.71 (Jun-2013) where the httputil2 lib is now included.

Anyway the line:
B4X:
j.GetRequest.SetContentType("application/soap+xml; charset=utf-8")
will not compile. The error is:

B4X:
Parsing code.                           0.02
Compiling code.                         Error
Error compiling program.
Error description: Unknown type: anywheresoftware.b4a.http.HttpClientWrapper.HttpUriRequestWrapper
Are you missing a library reference?
Occurred on line: 35
    j.GetRequest.SetContentType("application/soap+xml; charset=utf-8")
Word: setcontenttype
I have included the httputils2 (2.01) and stringutils (1.02) in the libs
Ideas?
 

JakeBullet70

Well-Known Member
Licensed User
Yep, that fixed it, could of sworn I tried that. Oh well. :sign0161:
 
Last edited:
Top