Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my table images are in binary format,want to retrieve images using wcf services and linq to sql concepts. and want to bind the images in multiple locations of webpage. how to get the images can anyone help me...
Posted
Comments
[no name] 7-Mar-12 5:37am    
Have you configured the WCF service and got the data from the table.

1. Create Service Method with return type as byte[]. This method ll return the image byte array from the DB-Table based on your conditions.
2. In page, Create byte[] variable to get output above service.
3. Follow the below steps
C#
Int32 offset =78;
byte[] imagews=wservice.getimage();
Int32 offset =78;
System.IO.MemoryStream ms = new System.IO.MemoryStream ();
ms.Write(imagews, offset, imagews.Length - offset);
System.Drawing.Bitmap imgJpg= new System.Drawing.Bitmap(ms);
imgJpg.Save(Server.MapPath ("FromDB.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg );
ms.Close();
ImageFromDB.ImageUrl = Server.MapPath("FromDB.jpg"); // this image can be used across the pages.
 
Share this answer
 
1. Getting data from database is not really WCF. It is job of ADO.Net. You can get the images from database using basic ADO.Net code. Lot of example can be found on MSDN and web in general to do this.
2. Once you have retrieved the image, I would suggest you send that to the client via service in binary format since that will be quicker. You can also take a look at "compressing images in .Net" if you are dealing with big pictures.
3. Check this[^] article. HTH.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900