WEB-Services / SOAP

Moderators: None (Apply to moderate this forum)
Number of threads: 108
Number of posts: 139

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
VB/JQuery webservice problem Posted by nodoid on 30 Oct 2010 at 8:13 AM
Hi,

I've hit a bit of a problem with a jQuery and a webservice. The webservice is in VB.NET and it's been quite a while since I last did anything in VB or a webservice.

Thing is, I'm not sure if the problem is in the query or in the code. All I get when I run is a button (which is correct) and after I click it, I get an error 500 - which doesn't really help.

The query (below) has security issues which I'm completely aware of - but as it's for my own use, that's ok - I can tidy that up at some point if I decide to use it.


    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>A quick and dirty hack</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#btnMore").click(function() {
                    $.ajax({
                            type:"POST",
                            contentType: "application/json; charset=utf-8",
                            url: "WebService1.asmx/GetData",
                            data: "{'localhost', 'paul', '', 'Database1', {'SELECT','Name','where','age > 25','and','hometown == Liverpool'}, {'','','',''}",
                            success: onSuccess,
                            error: onError
                          });
                });
            });
     
            function onSuccess(result)
            {
                $("#datalist").empty()
                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);
            }
     
        </script>
    </head>


I have a feeling that it's down to what I'm passing into the webservice rather than the webservice

    
<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("GetData")
            Dim constr As String = "server=" + server + "; uid=" + uid + "; pwd=" + pw + "; database=" + db
            Try
                connection = New SqlConnection(constr)
                connection.Open()
                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
                    dataadapter.TableMappings.Add("Table", tbl(i).ToString())
                    dataadapter.Fill(data)
                    Return data
                Next
     
            Catch ex As System.Data.SqlClient.SqlException
                Throw
            End Try
            connection.Close()
        End Function
     
        Private Function MySQLException(ByVal p1 As String) As Exception
            Throw New NotImplementedException
        End Function
     
    End Class


I'm using VS2010 and if I set a debug point in the VB webservice, it comes up with a webpage which gives me the method but the error is odd - it's saying the parameters needed have to be primitives rather than generics. I know I can pass generics into a webservice in C#, so I'm wondering if this is a VB problem more than anything.

The database has been set up in VS2010, so I'm assuming it's an mssql one so the connection code should be right (though the connection string may not be - the database is called Database1 and I'm using Table1 - do I pass Database1 or Table1 in via the jQuery?)

Any help, advice or pointers in the right direction on this would be appreciated. It's been ages since I've done any webservices and possibly longer since doing anything in anger with VB.NET!

Paul

P.S. I originally posted this on the webserver forum... sorry...
Thread Tree
nodoid VB/JQuery webservice problem on 30 Oct 2010 at 8:13 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.