Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid getting images from WCF Rest Service
    primarykey
    data
    text
    <p>I am pretty new to both Android and WCF. I am making a user table with a very small image in the sql server db as varbinary. In my service I have the following OperationContract:</p> <pre><code> [OperationContract] [WebGet(UriTemplate = "users/{emailAddress}/Image", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] System.IO.Stream GetImage(string emailAddress); </code></pre> <p>Implementation:</p> <pre><code> public System.IO.Stream GetImage(string emailAddress) { //parse personID, call DB string query = "Select profilePic from Flows_Users WHERE emailAddress= @emailAddress"; SqlConnection objConnection = new SqlConnection(); DataSet ObjDataset = new DataSet(); SqlDataAdapter objAdapater = new SqlDataAdapter(); SqlCommand objCommand = new SqlCommand(query, objConnection); objCommand.Parameters.Add("emailAddress", SqlDbType.NVarChar).Value = emailAddress; objConnection.ConnectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ToString(); objConnection.Open(); byte[] pic = (byte[])objCommand.ExecuteScalar(); objConnection.Close(); // if (pic == null) // return null; OutgoingWebResponseContext context = WebOperationContext.Current.OutgoingResponse; // //if (image_not_found_in_DB) // //{ // // context.StatusCode = System.Net.HttpStatusCode.Redirect; // // context.Headers.Add(System.Net.HttpResponseHeader.Location, url_of_a_default_image); // // return null; // //} //// everything is OK, so send image context.Headers.Add(System.Net.HttpResponseHeader.CacheControl, "public"); context.ContentType = "image/jpeg"; // context.LastModified = date_image_was_stored_in_database; context.StatusCode = System.Net.HttpStatusCode.OK; return new System.IO.MemoryStream(pic); } </code></pre> <p>Is there any way to read this into an Android Image View? I was unable to do it the base64 JSON way because the string kept terminating every time I tried to put it in a JSONArray.</p> <p>Any help would be appreciated, I have been working on this since Saturday. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload