[英]Decoding encoded URLs
我正在WCF中创建Rest服务。 我有一个方法GetUserDetails
,它接受三个参数GetUserDetails/?username={username}&mobileno={mobileno}&imeino={imeino}
。
但是我无法解析此编码的URL:
本地主机:9005 / Service.svc / GetUserDetails?request_header = null&request_body =%7B%22mobileNo%22%3A%229827098270%22%2C%22username%22%3A%22member%22%2C%22imeiNo%22%3A%22111111%22 %7D
由具有json格式参数的Get Request组成。 下面是我的代码详细信息:
[ServiceContract]
public interface IService
{
[OperationContract]
[FaultContract(typeof(string))]
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "GetUserDetails/?username={username}&mobileno={mobileno}&imeino={imeino}")]
UserModel GetUserDetails(string username, string mobileno, string imeino);
}
public class Service : IService
{
public UserModel GetUserDetails(string username, string mobileno, string imeino)
{
try
{
con = new SqlConnection(strcon);
if (con.State == ConnectionState.Open)
{
con.Close();
}
SqlCommand cmd = new SqlCommand("SP_AND_userprofiledata",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@mobileNo", mobileno);
cmd.Parameters.AddWithValue("@imeiNo", imeino);
da = new SqlDataAdapter();
da.SelectCommand = cmd;
ds = new DataSet();
da.Fill(ds);
}
}
任何帮助是极大的赞赏。
显然,它可以:
“对于RESTful服务,WCF提供了一个名为System.ServiceModel.WebHttpBinding的绑定。该绑定包括一些知识,这些知识知道如何使用HTTP和HTTPS传输来读写信息,以及编码适合与HTTP一起使用的消息。”
从这里 。
参见: http : //www.stackoverflow.com/questions/1187744/does-wcf-automatically-url-encode-decode-streams/1507218#1507218
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.