[英]How to pass parameters using Query string in a Soap web service?
This is my first web service, written using .NET 4.6. 这是我使用.NET 4.6编写的第一个Web服务。
I'm using System.Web.Services.WebService
. 我正在使用
System.Web.Services.WebService
。
How can I pass parameter in query string to a web service ? 如何将查询字符串中的参数传递给Web服务?
If I call the URL: http://localhost:11111/myWebService.asmx/GetWorldById
and try to pass also parameters like 如果我调用URL:
http://localhost:11111/myWebService.asmx/GetWorldById
并尝试也传递诸如
http://localhost:111/myWebService.asmx/GetWorldById?worldid=1 HTTP://本地主机:111 / myWebService.asmx / GetWorldById的WorldID = 1
I got error: Request format is unrecognized for URL unexpectedly ending in '/GetWorldById'
我收到错误消息:
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));
}
you can always read parameters from the requests 您可以随时从请求中读取参数
int worldid = int.Parse(HttpContext.Current.Request[nameof(worldid)]); int worldid = int.Parse(HttpContext.Current.Request [nameof(worldid)]);
but you need a post request anyway. 但是您仍然需要发帖请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.