3
나는 안드로이드와 WCF를 처음 접했습니다. varbinary 같이 SQL Server 데이터베이스에서 매우 작은 이미지를 사용하여 사용자 테이블을 만들고 있습니다. 내 서비스에서 나는 다음과 같은 OperationContract가 있습니다안드로이드와 WCF에서 이미지 가져 오기 안심 서비스
[OperationContract]
[WebGet(UriTemplate = "users/{emailAddress}/Image", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
System.IO.Stream GetImage(string emailAddress);
구현 :
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);
}
안드로이드 이미지보기에이 글을 읽을 수있는 방법이 있습니까? 문자열을 JSONArray에 넣으려고 할 때마다 문자열이 종료되기 때문에 base64 JSON 방식으로 할 수 없습니다.
도움이 될만한 데, 토요일 이후로 계속 노력하고 있습니다.