Click here to Skip to main content
11,927,378 members (52,357 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# SQL WCF LINQ C#4.0 ASP.NET4
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 7-Mar-12 0:33am
Navin Kumar.K.Subramanian 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.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