我创建了一个如下所示的asmx web-service:
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetEmployeesJSONByID(int sId)
{
try {
string sResult = string.Empty;
List<Employee> lstEmp = new List<Employee>();
List<Employee> lstEmpNew = new List<Employee>();
lstEmp.Add(new Employee { Id = 101, Name = "Nitin", Salary = 10000 });
lstEmp.Add(new Employee { Id = 102, Name = "Dinesh", Salary = 20000 });
switch (sId) {
case 101:
lstEmpNew.Add(new Employee { Id = 101, Name = "Nitin", Salary = 10000 });
break;
case 102:
lstEmpNew.Add(new Employee { Id = 102, Name = "Dinesh", Salary = 20000 });
break;
default:
break;
}
JavaScriptSerializer js = new JavaScriptSerializer();
sResult = js.Serialize(lstEmpNew);
Context.Response.Write(sResult);
} catch (Exception ex) {
Context.Response.Write(ex.Message.ToString());
}
}
我想通过Postman测试这个Web服务。所以我在我的本地IIS上部署了它,并在Postman中进行了如下配置:
我在URL中输入了:
http://XXXXXX/SampleWebService/Service.asmx/GetEmployeesJSONByID?sId=101
我遇到了“请求格式无效”的问题。在postman中如何传递sId来测试此Web服务?
webservices
以使用 HttpGet? - wazz