{"id":24541,"date":"2017-01-21T19:55:40","date_gmt":"2017-01-21T18:55:40","guid":{"rendered":"http:\/\/help.qualiware.it\/qw-help\/?p=24541"},"modified":"2017-09-21T20:24:12","modified_gmt":"2017-09-21T18:24:12","slug":"webservice-lettura-di-dati-da-mostrare-allutente-in-una-lista-di-scelta","status":"publish","type":"post","link":"https:\/\/help.qualiware.it\/qw-help\/webservice-lettura-di-dati-da-mostrare-allutente-in-una-lista-di-scelta\/","title":{"rendered":"WebService: lettura di dati da un servizio SOAP"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">' In questo esempio si fa riferimento al metodo ExecuteQuery dei WebServices di QualiWare, che rispettano lo standard SOAP\r\n' Vengono letti dati da una tabella e mostrati all'utente in una lista di scelta.\r\n\r\n' Creazione dell'XML con la richiesta.\r\n' NOTA: NON MODIFICARE la URL \"http:\/\/www.qualiware.it\/webservices\" mettendo al suo posto la URL del server!!! Altrimenti si ottiene l'errore 500.\r\n Dim xml As XML.Linq.XDocument = System.XML.Linq.XDocument.Parse(\"&lt;?xml version=\"\"1.0\"\" encoding=\"\"utf-8\"\"?&gt;\"+\r\n                                        \"&lt;soap:Envelope xmlns:soap=\"\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"\" xmlns:xsi=\"\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\" \r\nxmlns:xsd=\"\"http:\/\/www.w3.org\/2001\/XMLSchema\"\"&gt;\"+\r\n                                        \"&lt;soap:Body&gt;\"+\r\n                                            \"&lt;ExecuteQuery xmlns=\"\"http:\/\/www.qualiware.it\/webservices\/\"\"&gt;\"+\r\n                                                    \"&lt;DB&gt;XXXXXX&lt;\/DB&gt;\"+\r\n                                                    \"&lt;UserCode&gt;XXXXXXX&lt;\/UserCode&gt;\"+\r\n                                                    \"&lt;PassWord&gt;XXXXXXX&lt;\/PassWord&gt;\"+\r\n                                                    \"&lt;SQL&gt;SELECT CODICE,NOME from PERSON&lt;\/SQL&gt;\"+\r\n                                            \"&lt;\/ExecuteQuery&gt;\"+\r\n                                        \"&lt;\/soap:Body&gt;\"+\r\n                                        \"&lt;\/soap:Envelope&gt;\")\r\n\r\nDim url As String = \"http:\/\/www.qualiware.it\/webservices\/webservices.asmx\" ' URL del servizio\r\n\r\nDim webRequest__1 As Net.HttpWebRequest = DirectCast(Net.WebRequest.Create(url), Net.HttpWebRequest)\r\nwebRequest__1.Method = \"POST\"\r\nwebRequest__1.Credentials = New Net.NetworkCredential(\"&lt;nome utente&gt;\", \"&lt;password&gt;\", \"&lt;dominio&gt;\") ' Questa riga non \u00e8 necessaria se l'autenticazione \u00e8 anonima\r\nwebRequest__1.ContentType = \"text\/xml; charset=UTF-8\"\r\nwebRequest__1.ContentLength = xml.ToString().Length\r\nwebRequest__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\r\nUsing requestWriter2 As New IO.StreamWriter(webRequest__1.GetRequestStream())\r\n      requestWriter2.Write(xml.ToString())\r\nEnd Using\r\n\r\n' Recupero della risposta\r\nDim response As XML.Linq.XElement\r\nDim ok as boolean=true\r\nUsing resp As Net.HttpWebResponse = DirectCast(webRequest__1.GetResponse(), Net.HttpWebResponse)\r\n     if resp.StatusCode=200\r\n        Using responseStream = resp.GetResponseStream()\r\n              response = System.XML.Linq.XElement.Load(responseStream)\r\n        End Using\r\n     else\r\n        dim msg as string=\"Errore durante la connessione al Web Service.\"+vbcr+\"Status: \"+ltrim(str(resp.StatusCode))+\" \"+resp.StatusDescription\r\n        form.alert(msg)\r\n        ok=false\r\n     end if\r\nEnd Using\r\n\r\nif not ok\r\n   return\r\nend if\r\n' Elaborazione della risposta e trasformazione in una DataTable\r\nDim t As New System.data.DataTable\r\nDim c As System.data.DataColumn\r\nDim row As System.data.DataRow\r\nDim i As Integer\r\n\r\n' Crea la struttura della tabella\r\nDim ns As XML.Linq.XNamespace = \"http:\/\/www.qualiware.it\/webservices\/\"\r\nFor Each el As XML.Linq.XElement In response.Descendants(ns + \"Fields\")\r\n    For Each f As XML.Linq.XElement In el.Nodes\r\n        c = New System.data.DataColumn\r\n        c.ColumnName = f.Value\r\n        c.MaxLength = 50\r\n        t.Columns.Add(c)\r\n    Next\r\nNext\r\n\r\nFor Each el As XML.Linq.XElement In response.Descendants(ns + \"Rows\")\r\n    For Each r As XML.Linq.XElement In el.Nodes\r\n        row = t.NewRow\r\n        i = 0\r\n        For Each f As XML.Linq.XElement In r.Nodes\r\n            row(i) = f.Value\r\n            i += 1\r\n        Next\r\n\r\n        t.Rows.Add(row)\r\n    Next\r\nNext\r\n\r\nt.AcceptChanges()\r\n\r\n' Trasformazione della DataTable in una QWTable\r\ndim Q as new QWTable()\r\nQ.RequestLive = False\r\nQ.Table = t\r\nQ.Rowset = New QWRowset(Q)\r\n\r\n' Proposta all'utente dei records recuperati\r\nform.ChooseRecords(form.findcontrol(\"RitornoChooseRecords\"),Q,\"Scegliere\")\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; In questo esempio si fa riferimento al metodo ExecuteQuery dei WebServices di QualiWare, che rispettano lo standard SOAP &#8216; Vengono letti dati da una tabella e mostrati all&#8217;utente in una lista di scelta. &#8216; Creazione dell&#8217;XML con la richiesta. &#8216; NOTA: NON MODIFICARE la URL &#8220;http:\/\/www.qualiware.it\/webservices&#8221; mettendo al suo posto la URL del server!!!&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"ngg_post_thumbnail":0,"footnotes":""},"categories":[65],"tags":[71],"acf":[],"_links":{"self":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/24541"}],"collection":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/comments?post=24541"}],"version-history":[{"count":0,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/24541\/revisions"}],"wp:attachment":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/media?parent=24541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/categories?post=24541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/tags?post=24541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}