{"id":26184,"date":"2020-07-22T08:58:02","date_gmt":"2020-07-22T06:58:02","guid":{"rendered":"http:\/\/help.qualiware.it\/qw-help\/?p=26184"},"modified":"2020-07-22T08:58:02","modified_gmt":"2020-07-22T06:58:02","slug":"webservice-lettura-di-dati-da-un-servizio-soap-zucchetti","status":"publish","type":"post","link":"https:\/\/help.qualiware.it\/qw-help\/webservice-lettura-di-dati-da-un-servizio-soap-zucchetti\/","title":{"rendered":"WebService: lettura di dati da un servizio SOAP Zucchetti Evotre"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">' Il seguente snippet consente di importare dati da un web service Zucchetti Evotre.\r\n' Come si pu\u00f2 vedere dall'esempio di risposta XML, la struttura \u00e8 un po' particolare in quanto l'XML con i dati \u00e8 contenuto all'interno di un valore stringa di ritorno, ed \u00e8 quello su cui deve essere fatto il parse.\r\n' Struttura della risposta XML:\r\n'&lt;soap:Envelope xmlns:soap=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"&gt;\r\n'   &lt;soap:Body&gt;\r\n'   &lt;evotre_anagrafica_QueryResponse xmlns=\"http:\/\/evotre_anagrafica.ws.localhost\/\"&gt;\r\n'   &lt;return&gt;&lt;![CDATA[&lt;?xml version=\"1.0\"?&gt;\r\n'       &lt;webRowSet xmlns=\"http:\/\/java.sun.com\/xml\/ns\/jdbc\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n'xsi:schemaLocation=\"http:\/\/java.sun.com\/xml\/ns\/jdbc http:\/\/java.sun.com\/xml\/ns\/jdbc\/webrowset.xsd\"&gt;\r\n'        &lt;properties&gt;\r\n'             --- PROPRIETA' GENERALI ---\r\n'        &lt;\/properties&gt;\r\n'        &lt;metadata&gt;\r\n'          &lt;column-count&gt;12&lt;\/column-count&gt;\r\n'          &lt;column-definition&gt;\r\n'              --- PROPRIETA' DELLE COLONNE ---\r\n'          &lt;\/column-definition&gt;\r\n'        &lt;\/metadata&gt;\r\n'        &lt;data&gt;\r\n'          &lt;currentRow&gt;\r\n'            --- DATI DEI SINGOLI CAMPI DELLE COLONNE ---\r\n'            &lt;columnValue&gt;&lt;\/columnValue&gt;\r\n'          &lt;\/currentRow&gt;\r\n'        &lt;\/data&gt;\r\n'      &lt;\/webRowSet&gt;]]&gt;&lt;\/return&gt;\r\n'   &lt;\/evotre_anagrafica_QueryResponse&gt;\r\n'  &lt;\/soap:Body&gt;\r\n'&lt;\/soap:Envelope&gt;\r\n\r\n' Formazione SOAP Request e interrogazione WS\r\nDim xml As System.XML.Linq.XDocument = System.XML.Linq.XDocument.Parse(\"&lt;?xml version=\"\"1.0\"\" encoding=\"\"utf-8\"\"?&gt;\" +\r\n                                    \"&lt;soapenv:Envelope xmlns:soapenv=\"\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"\" xmlns:evot=\"\"http:\/\/evotre_anagrafica.ws.localhost\/\"\"&gt;\" +\r\n                                    \"  &lt;soapenv:Header\/&gt; \" +\r\n                                    \" &lt;soapenv:Body&gt; \" +\r\n                                    \" &lt;evot:evotre_anagrafica_Query&gt; \" +\r\n                                    \" &lt;evot:m_UserName&gt;ws_qualiware&lt;\/evot:m_UserName&gt;\" +\r\n                                    \" &lt;evot:m_Password&gt;ws_qualiware&lt;\/evot:m_Password&gt; \" +\r\n                                    \" &lt;evot:m_Company&gt;001&lt;\/evot:m_Company&gt; \" +\r\n                                    \" &lt;evot:m_bCount&gt;0&lt;\/evot:m_bCount&gt; \" +\r\n                                    \" &lt;\/evot:evotre_anagrafica_Query&gt; \" +\r\n                                    \"&lt;\/soapenv:Body&gt; \" +\r\n                                    \"&lt;\/soapenv:Envelope&gt;\" )\r\n\r\n\r\nDim url As String = \"https:\/\/yy.xxxxxxxxxxxxx.it:443\/HRPORTAL\/servlet\/SQLDataProviderServer\/evotre_anagrafica\"\r\nDim webRequest__1 As System.Net.HttpWebRequest = DirectCast(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)\r\n\r\nwebRequest__1.Method = \"POST\"\r\nwebRequest__1.ContentType = \"text\/xml; charset=UTF-8\"\r\nwebRequest__1.ContentLength = xml.ToString().Length\r\nwebRequest__1.Headers.Add(\"SOAPAction\", \"\"\"evotre_anagrafica_Query\"\"\")\r\nUsing requestWriter2 As New System.IO.StreamWriter(webRequest__1.GetRequestStream())\r\n      requestWriter2.Write(xml.ToString())\r\nEnd Using\r\n\r\n\r\n' Recupero della risposta\r\nDim response As System.XML.Linq.XElement\r\nDim ok as boolean=true\r\nUsing resp As System.Net.HttpWebResponse = DirectCast(webRequest__1.GetResponse(), System.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\t\t  \r\nif not ok\r\n   return\r\nend if\r\n\r\n' *** NECESSARIO ULTERIORE PARSING DELLA RISPOSTA - XML DENTRO XML ***\r\nDim response2 As System.XML.Linq.XElement = System.XML.Linq.XElement.Parse(response)\r\n\r\n\r\n' Elaborazione della risposta e trasformazione in una DataTable\r\nDim t As System.data.DataTable = 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' Predispongo le colonne della DataTable\r\nDim ns As System.XML.Linq.XNamespace = \"http:\/\/java.sun.com\/xml\/ns\/jdbc\"\r\nFor Each el As System.XML.Linq.XElement In response2.Descendants(ns + \"column-name\")\r\n\tc = New System.data.DataColumn\r\n\tc.ColumnName = el.Value\r\n\t'form.alert(c.ColumnName)\r\n\tc.MaxLength = 100\r\n\tt.Columns.Add(c)\r\nNext\r\n\t\t  \r\n' Leggo i singolo \r\nFor Each el As System.XML.Linq.XElement In response2.Descendants(ns + \"currentRow\")\r\n\trow = t.NewRow\r\n\ti = 0\r\n\tFor Each f As System.XML.Linq.XElement In el.Nodes\r\n\t\trow(i) = f.Value\r\n\t\ti += 1\r\n   Next\r\n\tt.Rows.Add(row)\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\")<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; Il seguente snippet consente di importare dati da un web service Zucchetti Evotre. &#8216; Come si pu\u00f2 vedere dall&#8217;esempio di risposta XML, la struttura \u00e8 un po&#8217; particolare in quanto l&#8217;XML con i dati \u00e8 contenuto all&#8217;interno di un valore stringa di ritorno, ed \u00e8 quello su cui deve essere fatto il parse. &#8216;&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\/26184"}],"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=26184"}],"version-history":[{"count":1,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/26184\/revisions"}],"predecessor-version":[{"id":32087,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/posts\/26184\/revisions\/32087"}],"wp:attachment":[{"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/media?parent=26184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/categories?post=26184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/help.qualiware.it\/qw-help\/wp-json\/wp\/v2\/tags?post=26184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}