简体   繁体   English

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

[英]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.

相关问题 如何使用asp.net MVC 4将参数传递给SOAP Web服务 - How to pass parameters to SOAP web service using asp.net mvc 4 如何在不使用(?)符号的情况下将参数传递给其他Web服务? - How to pass parameters to rest web service without using the (?) Symbol? 如何通过URL将参数传递给Web服务 - How to pass parameters to web service via URL 如何使用[webinvoke]将大型json字符串传递到Web服务 - how to pass large json string to web service using [webinvoke] 如何将SOAP标头从客户端传递到Web服务 - How to pass a SOAP header from a client to a web service 如何使用特殊字符将参数传递给WCF Web服务? - How to pass the parameters to WCF Web Service with special characters? 如何在.net中创建服务SOAP Web服务? - how to make a service, SOAP web service in .net? 如何使用MVVM Light从一个页面传递查询字符串参数并在WP 7中获取另一个参数 - How to pass query string parameters from one page and get in another in WP 7 using MVVM Light 如何使用SOAP ENV调用远程Web服务并捕获Soap Exception - How Call remote web service using SOAP ENV and catch Soap Exception 如何将DateTime对象传递给从PHP用C#编写的Soap Web服务? - How can I pass a DateTime object to a Soap web service written with C# from PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM