I'm using this to hook my client application into my web service.
In addition, I'm looking at MSDN about reading GetResponse as per the first link.
Here's the code that I've got so far:
public ActionResult Index()
{
WebRequest request = WebRequest.Create("http://localhost:49474/api/Store/Get");
request.Method = "GET";
WebResponse response = request.GetResponse();
Stream stores = response.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader sr = new StreamReader(stores, encode);
Char[] read = new Char[1024];
int count = sr.Read(read, 0, 1024);
List<Store> storesList = new List<Store>();
while (count > 0)
{
// need to read the contents of the response strem into the above instantiated list of stores.
}
}
My API delivers data like this:
public HttpResponseMessage Get()
{
List<Store> stores = db.Stores.ToList();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, stores);
return response;
}
Frankly I'm not sure where to go next. The MSDN link writes it all to a string but my concerns are:
- How am I to know how many characters I need to read at a time for each record?
- How do I read the data sent by the API so that I can use it in my view?