WCF REST服务无法识别URI参数

时间:2014-08-19 11:37:07

标签: c# android wcf rest

我正在尝试开发一个与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不会返回任何内容。

1 个答案:

答案 0 :(得分:0)

发现问题。它是使用web.config文件。服务名称不正确。我多么愚蠢。