0. <%@ Webservice Language="C#" class="Images" %> 1. 2. using System; 3. using System.Web.Services; 4. using System.IO; 5. 6. [WebService(Namespace="http://rob.santra.com/webservices/public/images/", Description="Demonstration of using Base64 encoding, in a Web Service using the .NET Framework.")]
7. public class Images: System.Web.Services.WebService { 8. [WebMethod(Description="Get an Image using Base64 Encoding")] 9. public byte[] GetImage() { 10. return getBinaryFile("C://Inetpub//wwwroot//webservices//public//images//logo.gif"); 11. } 12. public byte[] getBinaryFile(string filename) { 13. if(File.Exists(filename)) { 14. try { 15. FileStream s=File.OpenRead(filename); 16. return ConvertStreamToByteBuffer(s); 17. } catch(Exception e) { 18. return new byte[0]; 19. } 20. } else { 21. return new byte[0]; 22. } 23. } 24. 25. public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream) { 26. int b1; 27. System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); 28. while((b1=theStream.ReadByte())!=-1) { 29. tempStream.WriteByte(((byte)b1)); 30. } 31. return tempStream.ToArray(); 32. } 33. }