I have a REST method on the Web API server that reads from a local-to-it MS Access table, and stores the values into a generic list, and passes that back:
public List<SiteMapping> GetSiteMappings(String userId, String pwd)
{
List<SiteMapping> siteMappings = new List<SiteMapping>();
string connStr =
string.Format(
@"Provider=Microsoft.ACE.OLEDB.12.0;User ID={0};Password={1};Data
Source=C:\CDBWin\DATA\CDBSetup.MDB;Jet OLEDB:System database=C:\CDBWin\Data\sscs.mdw", userId,
pwd);
using (var conn = new OleDbConnection(connStr))
{
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT site_no, location_num FROM t_sites order by site_no";
cmd.CommandType = CommandType.Text;
conn.Open();
using (OleDbDataReader oleDbD8aReader = cmd.ExecuteReader())
{
while (oleDbD8aReader != null && oleDbD8aReader.Read())
{
int siteNum = oleDbD8aReader["SiteNumber"] is DBNull
? 0
: Convert.ToInt16(oleDbD8aReader["SiteNumber"]);
string locationNum = oleDbD8aReader["location_num"] is DBNull
? string.Empty
: oleDbD8aReader["location_num"].ToString();
siteMappings.Add(new SiteMapping { SiteNumber = siteNum, LocationNumber =
locationNum });
}
}
}
}
return siteMappings;
}
public class SiteMapping
{
public int SiteNumber { get; set; }
public string LocationNumber { get; set; }
public string SiteName { get; set; }
}
I call it from the client (Windows CE / Compact Framework) like so:
public ArrayList FetchSiteMappings(string url)
{
HttpWebRequest httpwreq = SendHTTPRequestNoCredentials(url, HttpMethods.GET, String.Empty, "application/xml");
// Idea from https://stackoverflow.com/questions/12350670/how-to-extract-zipped-file-received-from-httpwebresponse
var response = httpwreq.GetResponse();
var responseStream = response.GetResponseStream();
responseStream. <= I'm stuck here
}
...but I don't know what to do with the response stream -- How do I convert what is passed back from a generic list to an ArrayList?
Here's the SendHTTPRequestNoCredentials() method, in case anybody's interested (or even if they're not):
public static HttpWebRequest SendHTTPRequestNoCredentials(string uri, HttpMethods method, string data, string contentType)
{
WebRequest request = null;
try
{
request = WebRequest.Create(uri);
request.Method = Enum.ToObject(typeof(HttpMethods), method).ToString();
request.ContentType = contentType;
((HttpWebRequest)request).Accept = contentType;
((HttpWebRequest)request).KeepAlive = false;
((HttpWebRequest)request).ProtocolVersion = HttpVersion.Version10;
if (method != HttpMethods.GET && method != HttpMethods.DELETE)
{
byte[] arrData = Encoding.UTF8.GetBytes(data);
request.ContentLength = arrData.Length;
using (Stream oS = request.GetRequestStream())
{
oS.Write(arrData, 0, arrData.Length);
}
}
else
{
request.ContentLength = 0;
}
}
catch (Exception ex)
{
String msgInnerExAndStackTrace = String.Format(
"{0}; Inner Ex: {1}; Stack Trace: {2}", ex.Message, ex.InnerException,
ex.StackTrace);
ExceptionLoggingService.Instance.WriteLog(String.Format("From
FileXferREST.SendHTTPRequestNoCredentials(): {0}", msgInnerExAndStackTrace));
}
return request as HttpWebRequest;
}
UPDATE
I've changed the SendHTTPRequestNoCredentials() method to return a HttpWebResponse instead of a HttpWebRequest (see Is there something missing from this (borrowed/adapted) code, or am I not seeing where a Get gets fired? for the (minimal) details in the Update there), so the FetchSiteMappings() method has also changed; it is now:
HttpWebResponse httpwresp = SendHTTPRequestNoCredentials(url, HttpMethods.GET, String.Empty, "application/xml");
httpwresp. <= what now???
It seems that this should work:
UPDATE
Yes, it did work; this test code:
...showed me this:
...and several more "pages" (message box instantiations) after that.