我是WCF Restful服务的新手,我使用两种不同的方法创建服务,一种具有单个参数,另一种具有多个参数。 这些是我的服务方法
[OperationContract]
[WebInvoke(UriTemplate = "Test", Method = "POST", ResponseFormat = WebMessageFormat.Json)]
Response Test(string p_user);
我正在使用asp.net中的上述方法
string service_url = "http://localhost:5022/MyService.svc/Test";
var p_data=txtBox1.Text;//Passing the parameter
string result = string.Empty;
WebRequest request = WebRequest.Create(service_url);
request.Method = "POST";
request.ContentType = "application/json";
byte[] bytedata = Encoding.UTF8.GetBytes(p_data);
request.ContentLength = bytedata.Length;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(bytedata, 0, bytedata.Length);
postStream.Close();
}
StreamReader responseStream = new StreamReader(request.GetResponse().GetResponseStream());
result = responseStream.ReadToEnd();
JavaScriptSerializer js = new JavaScriptSerializer();
var response = js.Deserialize<ServiceResponse>(result);
工作正常,现在我有另外一个方法,有多个参数,比如这个
[OperationContract]
[WebInvoke(UriTemplate = "Test2", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, Method = "POST", ResponseFormat = WebMessageFormat.Json)]
string Test2(string a, string b);
如何使用相同的消费代码传递多个参数?即如何为此方法制作p_data? 我已经尝试过使用UriTemplate =“Test / {a} / {b}”和UriTemplate =“Test?a = {a}&amp; b = {b}”,但是我在第一个和坏请求中找不到第二种情况。
另外我想问一下,我该如何调试服务方法?