Skip to main content
Home Forums Silverlight Programming Programming with .NET - General return a complex object from a web service to silverlight client
10 replies. Latest Post by venablc85 on June 19, 2008.
(0)
hereitcomes
Member
5 points
9 Posts
06-19-2008 6:34 AM |
Hey there,
I'm developing a photo service for users to upload their photos to a central server and be able to download them again in a client on another machine. I have developed an asmx web service which returns photos individually by a Base64 encoded string. How can I return the photo data AND the photo name in one go? Can I encode an object of a custom class and extract that again at the other end? Also, is isolated file storage limited to 1mb per file or 1mb total?
Thanks for any advice
SteveWong
Contributor
6343 points
1,281 Posts
06-19-2008 6:45 AM |
You can add name and other thing with a list
public List<string> get_photo{List<string> k = new List<string>();
k.Add(photo_base64);k.Add(photo_Name);k.Add(.....);
return k;}
06-19-2008 6:53 AM |
For the base64, suppose you have got a string
string Base64Image;
void GetImageCompleted...{ if (e.Error == null) { Base64Image = e.Result[0]; }}
//..... Decode here
if (Base64Image != null){ byte[] imageData = Convert.FromBase64String(Base64Image); MemoryStream ms = new MemoryStream(imageData); BitmapImage tempImage = new BitmapImage(); tempImage.setSource(ms); ms.Dispose(); Image resultImage = tempImage}
06-19-2008 8:44 AM |
thanks for your advice, but "e.Result" is a string and can't be cast to a List<string>, so e.Result[0] returns a char.... what am I doing wrong?
My web service is an asmx web application (developed in visual studio) which returns a string. The string is either an error string or a base64 encoded byte[] of photo data.
06-19-2008 9:07 AM |
06-19-2008 9:21 AM |
You said that already Steve, I'm assuming that's your recommendation for the web service method. That's fine, but on the silverlight end, you can only access the result as "e.Result", which is just a string, and I can't cast that back to a List<string>
06-19-2008 9:32 AM |
nope, are you using WCF Service?
[OperationContract] List<string> getphoto(...parameter here);
06-19-2008 9:34 AM |
no im using an asp.net web service
06-19-2008 9:47 AM |
Try to fetch it to XML
public string GetPhoto(){ XElement PhotoInfo= new XElement("PhotoInfo"); PhotoInfo.Add(new XElement("PhotoData", base64Image)); PhotoInfo.Add(new XElement("PhotoName", picName)); PhotoInfo.Add(new XElement("anyother...", something here...));
XDocument mydoc = new XDocument( new XDeclaration("1.0", "utf-8", "yes"), new XComment("Photo data"), PhotoInfo ); return mydoc.ToString();}
In Silverlight
if (e.Error == null) { string base64Image; string photoname; XDocument xd = XDocument.Parse(e.Result); var v = from g in xd.Descendants("PhotoInfo") select new { bImage = g.Element("base64Image").Value, pname = g.Element("PhotoName").Value, };
foreach (var itm in v) { base64Image = itm.bImage.Trim(); photoname = itm.pname.Trim(); }
06-19-2008 10:22 AM |
thanks very much Steve. I created a Photo class in my silverlight app with 2 string properties. then wrote "select new Photo" in the XDocument selections. Works now
Thank you!
venablc85
18 points
12 Posts
06-19-2008 10:57 AM |
The current quota for isolated storage is 1mb per an application (http://www.silverlight.net/QuickStarts/IsoStore/default.aspx)
However i did read somewhere that there will be the functionality in a later version to increase this programatically although i suspect this will involve ugly pop-up requesting the users permission. Not paticularly user friendly :-s