I have a wcf service with some methods I will post one for example:
[OperationContract]
[WebGet(
UriTemplate = "GetPlates",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
IList<string> GetPlates();
the class
public IList<string> GetPlates()
{
return new List<string>
{
"ag",
"asda"
};
}
in the activity
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();
}
I get null everyttime. If I acces the URL from my browser or from the emulator I get: ["ag","asda"].