SOAP textbox info

Discussion in 'Android Questions' started by sigster, Jul 28, 2012.

  1. sigster

    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
    Code:
    <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
    Code:
    <?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: Jul 28, 2012
  2. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
  3. sigster

    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 ?


    Regards
    Sigster
     
  4. Jost aus Soest

    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):
    Code:
    Sub xmlGetTagContent(xml As String, tag As StringAs 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.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    It is much better to use the XML library for XML parsing.
     
  6. sigster

    sigster Active Member Licensed User

    Thanks Jost aus Soest and Erle


    Regards
    Sigster
     
  7. AbbasMohammed

    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
     
  8. AbbasMohammed

    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:
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please use [ code ] [ /code ] tags (without spaces) when posting code.

    You should set the content type header:
    Code:
    job1.Initialize("Job1", Me)
    job1.PostString(
    "http://www.ezzylearning.com/services/CountryInformationService.asmx", str)
    jog1.GetRequest.SetContentType(
    "application/soap+xml")
     
  10. AbbasMohammed

    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 :

    Code:
    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
     
  11. AbbasMohammed

    AbbasMohammed Member Licensed User

  12. AbbasMohammed

    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
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    This code works:
    Code:
    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>
     
    DonManfred and AbbasMohammed like this.
  14. AbbasMohammed

    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
     
    DonManfred likes this.
  15. JakeBullet70

    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:
    Code:
    j.GetRequest.SetContentType("application/soap+xml; charset=utf-8")
    will not compile. The error is:

    Code:
    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?
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    You should add a reference to Http library.
     
  17. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

    Yep, that fixed it, could of sworn I tried that. Oh well. :sign0161:
     
    Last edited: Jun 6, 2013
  18. cqn210

    cqn210 New Member Licensed User

    if the webservices has no parm
    I DO LIKE THIS IN B4A IT OCCOUR THE ERROR OF NULLPOINT
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice