如何在SOAP Web服务中使用查询字符串传递参数



这是我的第一个使用.NET 4.6编写的Web服务。

我正在使用System.Web.Services.WebService

如何将查询字符串中的参数传递给Web服务?

如果我调用url: http://localhost:11111/myWebService.asmx/GetWorldById并尝试通过

之类的参数

http://localhost:111/mywebservice.asmx/getworldbyid?worldid = 1

我有错误:Request format is unrecognized for URL unexpectedly ending in '/GetWorldById'

这是我的代码

[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));
    }

您总是可以从请求读取参数

int worldId = int.parse(httpcontext.current.requrest [nameof(worldId(](;

,但无论如何您都需要一个邮政请求。

最新更新