Webservice Login

MoscovoPT

Member
Boa tarde.

Gostaria de uma ajuda, se possível.
Segui o tutorial de webservices mas não me consigo ligar através do mesmo. Ocorre o erro em baixo.
Também adicionei HU2_ACCEPTALL aos Conditional Symbols em Build Configurations para aceitar todas as ligações mas não resolveu o problema.

Erro:
ResponseError. Reason: java.net.ConnectException: Failed to connect to /XX.XXX.XXX.XXX:80, Response:

Muito obrigado.

Webservice Login:
#Region  Project Attributes
    #ApplicationLabel: TRails Portugal
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
  

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
  
    Check("John", "11111")
    StartActivity("Index")
  
End Sub

Sub Check(username As String, password As String)

    Dim XML As String
    XML=""
    XML = XML & "<?xml version='1.0' encoding='utf-8'?>"
    XML = XML & "<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'>"
    XML = XML & "<soap:Body>"
    XML = XML & "<CheckUser xmlns='http://75.119.136.162/WebServiceGeral/WebServiceGeral.asmx'>"
    XML = XML & "<username>"& username &"</username>"
    XML = XML & "<password>"& password &"</password>"
    XML = XML & "</CheckUser>"
    XML = XML & "</soap:Body>"
    XML = XML & "</soap:Envelope>"
  
    Dim ResultURL As String
    Dim j As HttpJob
    j.Initialize("",Me)
    j.PostString("http://XX.XXX.XXX.XXX/WebServiceGeral/WebServiceGeral.asmx",XML)
    j.GetRequest.SetContentType("text/xml; charset=utf-8")
    j.GetRequest.SetHeader("SOAPAction","'http://XX.XXX.XXX.XXX/WebServiceGeral/WebServiceGeral.asmx/CheckUser'")
  

    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        ResultURL = j.GetString
    Else
        ResultURL = j.ErrorMessage
    End If
    j.Release
  
End Sub
 

Num3

Member
Licensed User
Viva companheiro,

Em primeiro lugar tens o ip no xml.

Pelo erro, tens um problema de connecção web (mas eu através do browser consegui abrir a página).

Cheira-me que deve ser algum setting no servidor e não no código.

Uma das coisas que reparei é que tens pelicas simples em vez de duplas no setheader, será disso?

de:
B4X:
"'http://XX.XXX.XXX.XXX/WebServiceGeral/WebServiceGeral.asmx/CheckUser'"

para:
B4X:
"http://XX.XXX.XXX.XXX/WebServiceGeral/WebServiceGeral.asmx/CheckUser"
 

MoscovoPT

Member
Num3,

Já ficou resolvido :)
Já consigo autenticar-me. No forum inglês já me deram umas dicas e cosnegui resolver.
Aqui fica a solução para quem precisar...

Muito obrigado.

Webservice to Login:
Sub Check(username As String, password As String)

    Dim XML As String
    XML = $"<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
    <CheckUser xmlns="http://XXX.XXX.XXX.XXX/WebServiceGeral/WebServiceGeral.asmx">
    <username>${username}</username>
    <password>${password}</password>
    </CheckUser>
      </soap:Body>
    </soap:Envelope>"$
    Dim ResultURL As String
    Dim j As HttpJob
    j.Initialize("",Me)
    j.PostString("http://XXX.XXX.XXX.XXX/WebServiceGeral/WebServiceGeral.asmx", XML)
    j.GetRequest.SetContentType("text/xml; charset=utf-8")

    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        ResultURL = j.GetString
        Log(ResultURL)
        Flag = xmlGetTagContent(ResultURL,"CheckUserResult")
        If ( Flag = "true") Then
            StartActivity(Index)
        Else
            StartActivity("Main")
        End If
    Else
        ResultURL = j.ErrorMessage
        Log(j.ErrorMessage)
    End If
    j.Release
   
End Sub

Public 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
 
Top