WCF REST服务不能识别URI参数
本文关键字:URI 参数 识别 不能 REST 服务 WCF | 更新日期: 2023-09-27 18:18:50
我正在尝试开发一个与WCF服务交互的android应用程序。我查看了可能发送的格式,但服务似乎无法识别参数并调用指定的函数。
WCF代码:public interface IEmployeeService
{
[OperationContract]
[WebGet(UriTemplate = "/GetEmployees/{LocationId}/{SessionId}/{CompanyId}",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
List<Employee> GetEmployees(string LocationId,string SessionId,string CompanyId);}
Android侧代码:
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Accept", "application/json");
httpGet.setHeader("Content-type", "application/json");
try {
HttpResponse execute = client.execute(httpGet);
HttpEntity responseEntity = execute.getEntity();
Reader employeeReader = new InputStreamReader(execute.getEntity().getContent());
char[] buffer = new char[(int) execute.getEntity().getContentLength()];
//fill the buffer by the help of reader
employeeReader.read(buffer);
//close the reader streams
employeeReader.close();
它生成的URI是这样的:EmployeeService.svc/GetEmployees/1311000032/2014/1312
,我也尝试了其他格式(如/GetEmployees/?LocationId={LocationId}&SessionId={SessionId}
)
我已经使用控制台应用程序检查了服务,并将参数传递给服务的引用,得到了正确的结果。但是使用URI什么也不返回。
找到问题。它与网络有关。配置文件。服务名称不正确。我真笨。