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
'-------------------------------------------------------------------------
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
'-------------------------------------------------------------------------