Italian Come consumare un Web Services Aspx con B4A

cocale2001

Member
Licensed User
Longtime User
Allego sorgente classe file wsSoap.bas. Commenti e modifiche ben accetti
Ciao a tutti

'-------------------------------------------------------------------------
Type=Class
Version=2.71
@EndOfDesignText@
'Class module
Sub Class_Globals
Dim parser As SaxParser
Dim webClient As HttpClient
Dim wsServiceName As String = ""
Dim wsServiceHost As String = ""
Dim wsError As Boolean = False
Dim wsValue As String = ""
Dim webRequest As HttpRequest
Dim objParent As Object
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(WScaller As Object ,WStitle As String ,WSURLhost As String, WSname As String, WSParamName() As String, WSParamValue() As String )
If WStitle = "" Then WStitle = WSname
wsServiceHost = WSURLhost
wsServiceName = WSname
wsError = False
wsValue = ""
objParent = WScaller
' -- init oggetto web client
ProgressDialogShow("Waiting services '" & WStitle & "' ...")
createWSS(wsServiceHost, wsServiceName, WSParamName, WSParamValue)
webClient.InitializeAcceptAll("webClient")
If webClient.Execute(webRequest, 1) = False Then wsError = True
End Sub
Public Sub WSSgetValue(URLhost As String, WSname As String, WSParamName() As String, WSParamValue() As String) As Boolean


End Sub
Sub createWSS(URLhost As String, WSname As String, WSParamName() As String, WSParamValue() As String)
Dim webRequest As HttpRequest
Dim requestSoapXML As String
Dim i As Int
'
requestSoapXML = ""
requestSoapXML = requestSoapXML & "<?xml version=""1.0"" encoding=""utf-8""?>"
requestSoapXML = requestSoapXML & "<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"">"
requestSoapXML = requestSoapXML & " <soap12:Body>"
requestSoapXML = requestSoapXML & " <" & WSname & " xmlns=""http://tempuri.org/"">"
For i = 0 To WSParamName.Length -1
requestSoapXML = requestSoapXML & " <" & WSParamName(i) & ">" & WSParamValue(i) & "</" & WSParamName(i) & ">"
Next
requestSoapXML = requestSoapXML & " </" & WSname & ">"
requestSoapXML = requestSoapXML & " </soap12:Body>"
requestSoapXML = requestSoapXML & "</soap12:Envelope>"


webRequest.InitializePost2(URLhost, requestSoapXML .GetBytes("UTF8"))
webRequest.SetHeader("Content-Type", "application/soap+xml; charset=utf-8")
webRequest.SetHeader("SOAPAction", "")
webRequest.Timeout = 60000
'
End Sub
Sub webClient_ResponseSuccess (Response As HttpResponse, TaskId As Int)
' -- se execute web cliente ha successo
' scrive risposta su file con nome = taskid
Response.GetAsynchronously("Response", File.OpenOutput(File.DirInternal, TaskId, False),True, TaskId)
End Sub

Sub webClient_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
' -- se execute web cliente non a successo estrae errore
wsError = True
wsValue = Response.GetString("UTF8")
End Sub

Sub Response_StreamFinish (Success As Boolean, TaskId As Int)
' -- alla fine della ricezioni dati li recupera dal file temporaneo.
' Li carica In var e cancella il File temporaneo
parser.Initialize
Dim In As InputStream
In = File.OpenInput(File.DirInternal , TaskId)
parser.Parse(In, "parser")
In.Close
' -- cancella il file temp
File.Delete( File.DirInternal , TaskId)
Dim wsValueRet As Object = wsValue

If wsError Then
' -- con erorri genera evento 'nomservices_error' se dichiarato sul chiamante
If SubExists( objParent, wsServiceName & "_error") Then
CallSubDelayed2(objParent, wsServiceName & "_error", wsValueRet)
End If
Else
' -- senza erorri genera evento 'nomservices_complete' se dichiarato sul chiamante
If SubExists( objParent, wsServiceName & "_complete") Then
CallSubDelayed2(objParent, wsServiceName & "_complete", wsValueRet)
End If
End If
ProgressDialogHide
End Sub

Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)

End Sub

' Funzione chiamata alla fine di ogni elemento
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
wsError = False
wsValue = Text
End Sub
'-------------------------------------------------------------------------
 

cocale2001

Member
Licensed User
Longtime User
Il web services ws_framework.asmx è stato creato con VisualStudio 2010 ed usato sia su personal web server che su IIS 7.5

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim wss As wsSoap
End Sub

Sub button1_Click
'
'
' -- attivare un WS
Dim wsArgName(3) As String
Dim wsArgValue(3) As String
Dim MainUrl As String = "http://192.168.35.25/wservices/ws_framework.asmx"

wsArgName(0) ="utente"
wsArgValue(0) = "PAOLOB"
wsArgName(1) ="passwd"
wsArgValue(1) = ""
wsArgName(2) ="azie"
wsArgValue(2) = "CE"

wss.Initialize (Me, "Login",MainUrl, "login_a", wsArgName, wsArgValue)
End Sub

' -- login_a è il nome della funzione con cui vengono chiatati gli eventi :
'login_a_complete
'login_a_error
' -- controlla la classe wsSoap dove vengono eseguite le funzioni 'CallSubDelayed2'


Sub login_a_complete(value As String )
Dim aValue() As String

aValue = HGsql.getValueArray(value)
Msgbox (aValue(2),"Risultato")
'tab1.LoadTableFromCSVVariable(value, True)
'lblTotRow.Text = tab1.TotalRows
'HGsql.loadSQLcommand(value, HGvar.HGdb)
End Sub


Ciao
 

Gennaro Frungillo

Member
Licensed User
Longtime User
scusami se rispondo solo ora, ho fatto vaie prove ma non riesco proprio a capire che tipo di variabile viene fuori nell'evento _complete:
quel 'value as string' come faccio a leggerlo?

Saluti!
 
Top