[Mono-list] Webservice and jQuery problem

Paul F. Johnson paul at all-the-johnsons.co.uk
Wed Oct 27 20:43:24 EDT 2010


I'm stuck on this one as I think it's all more or less correct.

I have a very simple web service which sucks data from a database. On
the web page, I have a jQuery which produces a button, click it and data
should be brought back out.

Only problem is that it gives me an error 500

The webservice looks like this

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Collections
Imports System.Data
Imports System.Web
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Diagnostics
Imports System

' 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:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class WebService1
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetData(ByVal server As String, ByVal uid As String,
ByVal pw As String, _
                            ByVal db As String, ByVal cmds As ArrayList,
ByVal tbl As ArrayList) As DataSet
        Dim connection As SqlConnection
        Dim data As New DataSet("GetDataSet")
        Dim constr As String = "server=" + server + "; uid=" + uid + ";
pwd=" + pw + "; database=" + db
            connection = New SqlConnection(constr)
            For i = 0 To cmds.Count
                If (Not (cmds(i).ToString()).StartsWith(("SELECT" Or
"Select"))) Then
                    Throw MySQLException("The SQL command must start
with SELECT or Select")
                End If
                Dim command As New SqlCommand
                command.Connection = connection
                command.CommandText = cmds(i).ToString()
                Dim dataadapter As New SqlDataAdapter
                dataadapter.SelectCommand = command
                Return data

        Catch ex As System.Data.SqlClient.SqlException
        End Try
    End Function

    Private Function MySQLException(ByVal p1 As String) As Exception
        Throw New NotImplementedException
    End Function

End Class

Public Class MySQLException
    Inherits System.Exception
    Public MySqlException(Message) As ApplicationException
End Class

with the jQuery looking like this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>A quick and dirty hack</title>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#btnMore").click(function() {
                        contentType: "application/json; charset=utf-8",
                        url: "WebService1.asmx/GetData",
                        data: "{'localhost', 'root', '', 'Table1',
{'SELECT','Name','where','age > 25','and','hometown == Liverpool'},
                        success: onSuccess,
                        error: onError

        function onSuccess(result)
            var strings = result.d;
            for (var i = 0; i < strings.length; ++i)
                $("#datalist").append("<li>" + strings[i] + "</li>");

        function onError(result)
            alert(result.status + ": " + result.statusText);

<form id = "form1" runat="server">
<ul id="datalist"></ul>
<br />
<input type="button" id="btnMore" value="do it" />


The only part which I think is wrong is the passing in of tbl to the
webservice. Do I need to pass in a something corresponding to the
correct field type here?

Be gentle, this is my first webservice!


Vertraue mir, ich weiss, was ich mache...

More information about the Mono-list mailing list