0

This is my first web service, written using .NET 4.6.

I'm using System.Web.Services.WebService.

How can I pass parameter in query string to a web service ?

If I call the URL: http://localhost:11111/myWebService.asmx/GetWorldById and try to pass also parameters like

http://localhost:111/myWebService.asmx/GetWorldById?worldid=1

I got error: Request format is unrecognized for URL unexpectedly ending in '/GetWorldById'

This is my code

[WebMethod]
    public string GetWorldById(int worldid)
    {
        using (MySqlConnection db = new MySqlConnection(connString))
        {
            MySqlCommand cmd = new MySqlCommand("", db);
            MySqlDataReader dr;

            cmd.CommandText = "SELECT * FROM myTable WHERE worldid='" + param1+ "'";
            db.Open();
            dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                PopulateListFromDataReader(dr);

            }


        }

        JavaScriptSerializer js = new JavaScriptSerializer();
        return (js.Serialize(worldsList));
    }
1
  • Soap does not use url parameters, it uses xml payloads Commented Apr 28, 2018 at 9:12

1 Answer 1

1

you can always read parameters from the requests

int worldid = int.Parse(HttpContext.Current.Request[nameof(worldid)]);

but you need a post request anyway.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.