StealthRT
StealthRT

Reputation: 10552

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

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!

Upvotes: 1

Views: 568

Answers (2)

T.S.
T.S.

Reputation: 19386

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

Upvotes: 2

ndykman
ndykman

Reputation: 1

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.

Upvotes: 0

Related Questions