Click here to Skip to main content
11,796,393 members (71,467 online)
Rate this: bad
Please Sign up or sign in to vote.
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 6-Mar-12 23:33pm
Navin Kumar.K.Subramanian at 7-Mar-12 5:37am
Have you configured the WCF service and got the data from the table.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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
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 );
ImageFromDB.ImageUrl = Server.MapPath("FromDB.jpg"); // this image can be used across the pages.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

  Print Answers RSS
0 Maciej Los 570
1 Abhinav S 392
2 OriginalGriff 340
3 CPallini 269
4 KrunalRohit 249
0 OriginalGriff 2,012
1 Maciej Los 1,615
2 KrunalRohit 1,310
3 CPallini 1,015
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 9 Mar 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100