JSON via ASMX webservice

2 posts, 0 answers
  1. Mark
    Mark avatar
    2 posts
    Member since:
    Jan 2015

    Posted 27 Jan 2016 Link to this post

    The ASMX web service below returns a file that when saved and referenced in the RadClientDataSource displays correct on my RadMap. However all attempts to point the RadClientDataSource directly at the web service result in no data being displayed on the RadMap.

     Please help


    Imports System
    Imports System.Web
    Imports System.Collections
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Web.Script.Serialization
    Imports System.Web.Script.Services
    Imports System.ComponentModel
    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="d")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class SQLdataWH
    Inherits System.Web.Services.WebService
    <WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function getPBayMachinePopulation() As String
    Dim sqlConnection As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("BKDataWarehouseConnectionString").ConnectionString)
    Dim sqlCommand As SqlCommand = New SqlCommand("SELECT * FROM [BKDataWarehouse].[dbo].[uvw_PBAY_MachineLocationSummary]", sqlConnection)
    Dim sqlDataset As DataSet = New DataSet()
    Dim sqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(sqlCommand)
    'Dim MArray()() As String = New String(sqlDataset.Tables(0).Rows.Count - 1)() {}
    Dim MArray(sqlDataset.Tables(0).Rows.Count - 1) As JSON_results
    Dim i As Integer = 0
    For Each rs As DataRow In sqlDataset.Tables(0).Rows
    'MArray(i) = New String() {rs("Location").ToString(), rs("Population").ToString()}
    MArray(i) = New JSON_results
    MArray(i).City = rs("City")
    MArray(i).Country = rs("Country")
    MArray(i).Pop2010 = rs("Population")
    MArray(i).Location(0) = rs("LATITUDE")
    MArray(i).Location(1) = rs("LONGITUDE")
    i = i + 1
    Dim js As JavaScriptSerializer = New JavaScriptSerializer()
    Dim sJSON As String = js.Serialize(MArray)
    Return sJSON
    End Function
    Public Class JSON_results
    Private PoplationValue As Double
    Private CityValue As String
    Private CountryValue As String
    Private LocationValue(1) As Double
    Property Pop2010() As Double
    Return PoplationValue
    End Get
    Set(ByVal Value As Double)
    PoplationValue = Value
    End Set
    End Property
    Property City() As String
    Return CityValue
    End Get
    Set(ByVal Value As String)
    CityValue = Value
    End Set
    End Property
    Property Country() As String
    Return CountryValue
    End Get
    Set(ByVal Value As String)
    CountryValue = Value
    End Set
    End Property
    Property Location() As Double()
    Return LocationValue
    End Get
    Set(ByVal Value As Double())
    LocationValue = Value
    End Set
    End Property
    End Class
    'Public Class LocationType
    ' Private LatitudeValue As Double
    ' Private LongitudeValue As Double
    ' Property Latitude() As Double
    ' Get
    ' Return LatitudeValue
    ' End Get
    ' Set(ByVal Value As Double)
    ' LatitudeValue = Value
    ' End Set
    ' End Property
    ' Property Longitude() As Double
    ' Get
    ' Return LongitudeValue
    ' End Get
    ' Set(ByVal Value As Double)
    ' LongitudeValue = Value
    ' End Set
    ' End Property
    'End Class
    End Class

  2. Ianko
    Ianko avatar
    1828 posts

    Posted 01 Feb 2016 Link to this post

    Hi Mark,

    You can refer to this article to see how to connect RadClientDataSource to Web Service—http://docs.telerik.com/devtools/aspnet-ajax/controls/clientdatasource/connecting-to-web-service.

    After that, inspect the requests via the NET tab of teh browser's dev toobar and see whether request is being processed properly. 

Back to Top