1
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public string getUser(string[] username){
    string[] result= new string[5];
    string qry="";
    for(int i=0;i<5;i++)
    {
        username[i]= a;
        qry="SELECT * FROM USER WHERE USERNAME='" + a + "' ";
        result[i] = getjsondata(qry);
        return result[i];  
    }

}

When I try to execute a method, it shows the test form is only available for methods with primitive types as parameters. I tried out List as parameter, that also fails. I want to pass string[] as parameter to the WebMethod.

juanferrer
  • 1,192
  • 1
  • 16
  • 29
Dev
  • 315
  • 2
  • 16
  • The code as shown is vulnerable to SQL injection attacks and it won't work if a name contains an apostrophe. The code needs to be modified to use SQL parameters instead of string concatenation, which will solve both those issues. – Andrew Morton Jul 19 '17 at 14:39
  • Completely unrelated but I would consider using Web API, much more fluent, self documenting and a joy to work with. Took me a day to pick up the fundamentals and build a working solution. Also Entity Framework? If your bound by framework/work constraints. Please ignore. – Tez Wingfield Jul 19 '17 at 15:21

1 Answers1

0

You're using a GET operation, which only supports URL / querystring parameters.

For non-primitive parameter types you need to use the HTTP body. In order to use the body you should use a POST or one of the other HTTP operations.

See this answer for more details: Simple post to Web Api

Kirk Broadhurst
  • 27,836
  • 16
  • 104
  • 169