这可能非常简单,但我没有找到在我的 WCF 休息服务中读取查询字符串值的方法。我尝试了以下但没有快乐
HttpContext.Current.Request.QueryString["name"]
这可能非常简单,但我没有找到在我的 WCF 休息服务中读取查询字符串值的方法。我尝试了以下但没有快乐
HttpContext.Current.Request.QueryString["name"]
像这样的东西应该适合你。您需要使用 UriTemplate。以下是WCF服务
[服务合同] 接口IPing { [运营合同] [WebInvoke(Method="POST", UriTemplate="stuff?n={name}&q={quantity}")] void AddStuff(字符串名称、字符串数量、流数据); } 类 PingService : IPing { public void AddStuff(字符串名称、字符串数量、流数据) { Console.WriteLine("{0} : {1}", 名称, 数量); Console.WriteLine("数据 ..."); 使用 (StreamReader sr = new StreamReader(data)) { Console.WriteLine(sr.ReadToEnd()); } } }
和客户端
静态无效主要(字符串 [] 参数) { WebRequest req = WebRequest.Create("http://localhost:9000/ping/stuff?n=rich&q=20"); req.Method = "POST"; req.ContentType = "文本/html"; 使用 (StreamWriter sw = new StreamWriter(req.GetRequestStream())) { sw.WriteLine("你好"); } req.GetResponse(); }