Dear all,

I want to develop a webservice that returns a json like the following:

http://niceq8i.tv/mobile/api/cat/get_sounds

How to make the functions has a direct link like that and return the json code without any xml code

Thanks in advance...

Recommended Answers

All 4 Replies

vb.net

This is my webservice code. May be this will help you brother :)

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
Imports System.Collections.Generic

<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class commonWebservice
    Inherits System.Web.Services.WebService

    <WebMethod()> _
<ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json)> _
    Public Function getLocations(ByVal TariffCardId As String) As String
        Dim CN As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("xxxx").ConnectionString)
        CN.Open()
        Dim strQuery As String
            strQuery = "Select Location From tbl_Locations"

        Dim cmd As SqlCommand = New SqlCommand(strQuery, CN)
        Dim ds As DataSet = New DataSet()
        Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)

        da.Fill(ds)
        CN.Close()

        Dim MArray()() As String = New String(ds.Tables(0).Rows.Count)() {}
        Dim i As Integer = 0
        Dim str As String
        For Each rs As DataRow In ds.Tables(0).Rows
            ' MArray(i) = New String() {rs("Location").ToString()}
            'i = i + 1
            If str = "" Then
                str = rs("Location").ToString()
            Else
                str = str & "," & rs("Location").ToString()
            End If

        Next

        Dim js As JavaScriptSerializer = New JavaScriptSerializer()
        Dim sJSON As String = js.Serialize(MArray)
        Return str
    End Function

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.