我有一个 wcf 服务,其中包含一些我将发布的方法,例如:
[OperationContract]
[WebGet(
UriTemplate = "GetPlates",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
IList<string> GetPlates();
班上
public IList<string> GetPlates()
{
return new List<string>
{
"ag",
"asda"
};
}
在活动中
try {
// Send GET request to <service>/GetPlates
HttpGet request = new HttpGet(SERVICE_URI + "/GetPlates");
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity responseEntity = response.getEntity();
// Read response data into buffer
char[] buffer = new char[(int)responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
JSONArray plates = new JSONArray(new String(buffer));
} catch (Exception e) {
e.printStackTrace();
}
我每次都为空。如果我从浏览器或模拟器访问 URL,我会得到:["ag","asda"]。