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.

2
  • 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. Commented Jul 19, 2017 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. Commented Jul 19, 2017 at 15:21

1 Answer 1

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.