1

Hey all I am getting the error of:

Value of type 'String' cannot be converted to '1-dimensional array of String'.

On this line of my code:

Dim blah As String = webService.theQ(qString:="SELECT blah FROM table WHERE blah = 'hello'")

My web service sqlQ function code is:

<WebMethod(CacheDuration:=60)> _
<ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json, XmlSerializeString:=False)> _
Public Function theQ(ByVal qString As List(Of String)) As String
    Dim results As Object = fetchSQLQ("query", qString(0))
    ...etc etc
    Dim ser As New System.Web.Script.Serialization.JavaScriptSerializer()
    Dim strResponse As String = ser.Serialize(results)

    return strResponse
End Function

I'm not sure how to format it like its calling for?

This is how I go about calling it using AJAX (and it works fine):

var sqlCC = "SELECT blah FROM table WHERE blah = 'hello'";

$.ajax({
    type : "POST",
    crossDomain : true,
    dataType : 'json',
    cache : false,
    contentType : "application/json",
    url : "/Service1.asmx/theQ",
    data : JSON.stringify({
        qString : [sqlCC]
    }),
    success : function (data2) {
        var obj2 = jQuery.parseJSON(data2);
    },
    error : function (xhr, status, error) {
        console.log(xhr.responseText);
    }
});

Any help would be great!

3
  • qString has type List(Of String) but you pass it only a string ; theQ is a Sub which produce no return value but you use it as a Function Commented Oct 23, 2015 at 17:59
  • @Sehnsucht check my OP for more of the web service code to explain better what I am returning. Commented Oct 23, 2015 at 18:06
  • @StealthRT Please see my answer - it explains what you do wrong Commented Oct 23, 2015 at 18:34

2 Answers 2

2

Your problem is parameter that you're passing to your webs service. You pass

webService.theQ(qString:="SELECT blah FROM table WHERE blah = 'hello'")

Where you assigning string to qString. But in your declaration

Public Sub theQ(ByVal qString As List(Of String))

qString is declared as list of strings.

And also, your web methos is a SUB which doesn't have any return value, therefore

Dim blah As List(Of String) = webService.theQ(. . . .

is not even legal

Sign up to request clarification or add additional context in comments.

Comments

0

The error pretty much says it all. The webservice call is returning a string, not a list of strings. If you look at your script code, it parses the result of the AJAX call as JSON. While I can't tell for sure from the rest of your code, it is quite possible that the webservice call is returning a JSON string as well.

Easy way to confirm:

Dim blah as String = webService.theQ(...)
' Print out the value of blah or inspect in debugger... 

If the string is JSON, then you'll have to parse it to get the list you seek.

1 Comment

Using Dim blah As String still has the same error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.