Hi Iwant to Upload image with textual information json and wcf the image contain a title and descrption any help please
the function which implemet the below interface i am working with json an wcf
public wsResultImage InsertPhoto(Stream JsonDataStream)
{
wsResultImage results = new wsResultImage();
StreamReader reader = new StreamReader(JsonDataStream);
string JSONdata = reader.ReadToEnd();
// bool logged;
// ..then convert the string into a single "wsOrder" record.
JavaScriptSerializer jss = new JavaScriptSerializer();
wsImage photoo = jss.Deserialize<wsImage>(JSONdata);
// byte[] bytes= (byte[]) (photoo.GetImage).ToArray();
if (photoo == null)
{
results.id = photoo.GetId;
results.titlee = photoo.GetTitle;
results.imag = photoo.GetImage;
results.descriptionn = photoo.GetDescrption;
results.message = "all fields are required";
return results;
}
FamissimaDataContext dc = new FamissimaDataContext();
/* imagees photo = (from p
in dc.imagees
select p).FirstOrDefault(); */
// byte[] bytes= (byte[]) (photoo.GetImage).ToArray();
// string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
// where (photoo.GetId = p.id)
byte[] imageBytes = Convert.FromBase64String(photoo.GetImage);
imagees newPhoto = new imagees()
{
id = photoo.GetId,
// imagee = System.Text.Encoding.ASCII.GetBytes(photoo.GetImage),
// imagee = imageBytes,
title = photoo.GetTitle,
description = photoo.GetDescrption,
};
dc.imagees.InsertOnSubmit(newPhoto);
dc.SubmitChanges();
// Console.WriteLine("Hello C# World :-) ");
results.message = "Success";
// result.Exception = "";
return results;
}
the interface:
[OperationContract]
[WebInvoke(Method= "Post", ResponseFormat = WebMessageFormat.Json, UriTemplate = "uploadimage")]
wsResultImage InsertPhoto(Stream JsonDataStream);