' In questo esempio si fa riferimento al metodo ExecuteQuery dei WebServices di QualiWare, che rispettano lo standard SOAP ' Vengono letti dati da una tabella e mostrati all'utente in una lista di scelta. ' Creazione dell'XML con la richiesta. ' NOTA: NON MODIFICARE la URL "http://www.qualiware.it/webservices" mettendo al suo posto la URL del server!!! Altrimenti si ottiene l'errore 500. Dim xml As XML.Linq.XDocument = System.XML.Linq.XDocument.Parse("<?xml version=""1.0"" encoding=""utf-8""?>"+ "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">"+ "<soap:Body>"+ "<ExecuteQuery xmlns=""http://www.qualiware.it/webservices/"">"+ "<DB>XXXXXX</DB>"+ "<UserCode>XXXXXXX</UserCode>"+ "<PassWord>XXXXXXX</PassWord>"+ "<SQL>SELECT CODICE,NOME from PERSON</SQL>"+ "</ExecuteQuery>"+ "</soap:Body>"+ "</soap:Envelope>") Dim url As String = "http://www.qualiware.it/webservices/webservices.asmx" ' URL del servizio Dim webRequest__1 As Net.HttpWebRequest = DirectCast(Net.WebRequest.Create(url), Net.HttpWebRequest) webRequest__1.Method = "POST" webRequest__1.Credentials = New Net.NetworkCredential("<nome utente>", "<password>", "<dominio>") ' Questa riga non è necessaria se l'autenticazione è anonima webRequest__1.ContentType = "text/xml; charset=UTF-8" webRequest__1.ContentLength = xml.ToString().Length webRequest__1.Headers.Add("SOAPAction", """http://www.qualiware.it/webservices/ExecuteQuery""") ' Azione da eseguire !IMPORTANTE: VA FRA DOPPI APICI E NON VA MODIFICATA METTENDO LA URL DEL SERVER AL POSTO DI www.qualiware.it/... ALTRIMENTI SI OTTIENE L'ERRORE 500 Using requestWriter2 As New IO.StreamWriter(webRequest__1.GetRequestStream()) requestWriter2.Write(xml.ToString()) End Using ' Recupero della risposta Dim response As XML.Linq.XElement Dim ok as boolean=true Using resp As Net.HttpWebResponse = DirectCast(webRequest__1.GetResponse(), Net.HttpWebResponse) if resp.StatusCode=200 Using responseStream = resp.GetResponseStream() response = System.XML.Linq.XElement.Load(responseStream) End Using else dim msg as string="Errore durante la connessione al Web Service."+vbcr+"Status: "+ltrim(str(resp.StatusCode))+" "+resp.StatusDescription form.alert(msg) ok=false end if End Using if not ok return end if ' Elaborazione della risposta e trasformazione in una DataTable Dim t As New System.data.DataTable Dim c As System.data.DataColumn Dim row As System.data.DataRow Dim i As Integer ' Crea la struttura della tabella Dim ns As XML.Linq.XNamespace = "http://www.qualiware.it/webservices/" For Each el As XML.Linq.XElement In response.Descendants(ns + "Fields") For Each f As XML.Linq.XElement In el.Nodes c = New System.data.DataColumn c.ColumnName = f.Value c.MaxLength = 50 t.Columns.Add(c) Next Next For Each el As XML.Linq.XElement In response.Descendants(ns + "Rows") For Each r As XML.Linq.XElement In el.Nodes row = t.NewRow i = 0 For Each f As XML.Linq.XElement In r.Nodes row(i) = f.Value i += 1 Next t.Rows.Add(row) Next Next t.AcceptChanges() ' Trasformazione della DataTable in una QWTable dim Q as new QWTable() Q.RequestLive = False Q.Table = t Q.Rowset = New QWRowset(Q) ' Proposta all'utente dei records recuperati form.ChooseRecords(form.findcontrol("RitornoChooseRecords"),Q,"Scegliere")