SIGN UP MEMBER LOGIN:    
ARTICLE

Webservice return the Image of the Customer in ASP.NET 2.0

Posted by Srinivas Articles | Web Services in C# May 11, 2009
Webservice return the Image of the Customer in ASP.NET 2.0
Reader Level:

Webservice returning image of the customer in ASP.NET 2.0

 

Now I will explain how to get the images from Oracle database and how to display it on the ASP.NET 2.0 web page.

 

In oracle images are saved as blob data type.

 

In my application I have written one webservice, it will send the signature image of the customer to the other application which is saved in my application database Oracle database.

 

Webservice will provide security for database when one application requires the data from other application. The application which requires the data will send a request to the webservice so the webservice will give the response depending on the customer input. In this way it will provide the security to out database.

 

The webservice code is looking like this:

 

The below webservice will take the Customer ID and return the signature of the customer to the other application which send the request to webservice.

 

This is the working code.

 

using System;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Data.OracleClient;

using System.IO;

using System.Data;

using Microsoft.ApplicationBlocks.Data;

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class Service : System.Web.Services.WebService

{

    public Service()

    {

 

    }

 

    [WebMethod]

    public string Image(int CustID)

    {

        OracleConnection con = new OracleConnection("Connection String");

        OracleCommand cmd = new OracleCommand();

        string imageString = "";

        int id = 0;

        OracleDataReader dr;

        cmd.Connection = con;

        cmd.CommandType = System.Data.CommandType.Text;

        cmd.CommandText = "select * from Customer_Table where CLIENT_ID= " + id;

        con.Open();

        dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

        int Cust_ID = CustID;

        byte[] arrpicture = new byte[0];

        string imageType = "";

        if (dr.Read())

        {

            arrpicture = (byte[])dr[2];

            imageType = dr[4].ToString();

        }

        con.Close();

 

        imageString = Convert.ToBase64String(arrpicture);

        string xml_String = "";

        xml_String = "<Signatures><Customer><CustID>" + Cust_ID + "</CustID><Signature>" + imageString + "</Signature><imageType>" + imageType + "</imageType></Customer></Signatures>";

        return xml_String;

    }

}

 

 

Now I will show how to display the signature image in ASP.NET 2.0 application.

 

Enter the customer ID of the customer and click on the signature button.

 

  a1.bmp
The out put will be looking like this.

a2.bmp
The code written under button click event is

 

protected void b1_Click(object sender, EventArgs e)

    {

        string res = "";

        int i = 0;

        string image = "";

        int CustID = Convert.ToInt32(t1.Text);

 

        Service a = new Service();

        res = a.Image(CustID);

 

        XmlDocument xDoc = new XmlDocument();

 

        xDoc.LoadXml(res);

 

        foreach (System.Xml.XmlNode x in xDoc.ChildNodes[0].ChildNodes)

        {

 

            XmlNodeList Signature = xDoc.GetElementsByTagName("Signature");

 

            image = Signature[i].InnerText;

 

            i++;

        }

 

        byte[] arrpicture = System.Convert.FromBase64String(image);

 

        Response.ContentType = "Image/BMP";

 

        Response.BinaryWrite(arrpicture);

    }

 

 

But it will override the data on the data on the webform.

 

Now I will explain how to display the blobe image on image control in ASP.NET 2.0.

 

Place the Image control on the webform Default.aspx as shown below.

 

<tr>

     <td>

          <asp:image ToolTip = "ASP Image Control" ID="Image4" runat="server" ImageUrl ="ImageCSharp.aspx?ImageID=1" Height="156px" Width="174px"></asp:image>

     </td>

</tr>

 

The imageulr property of the Image control we can call webform ImageCSharp.aspx as shown above.

 

protected void Page_Load(object sender, EventArgs e)

    {

        if (Request.QueryString["ImageID"] != null)

        {

            

            OracleConnection con = new OracleConnection("Connection_String");

            OracleCommand cmd = new OracleCommand();

 

            int id = 0;

     

            OracleDataReader dr;

 

            cmd.Connection = con;

            cmd.CommandType = System.Data.CommandType.Text;

            cmd.CommandText = "select * from Signature where CLIENT_ID= " + id;

 

            con.Open();

            dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

 

            byte[] arrpicture = new byte[0];

           

 

            if (dr.Read())

            {

                arrpicture = (byte[])dr[2];

                               Response.Buffer = true;

                Response.Charset = "";

                Response.Cache.SetCacheability(HttpCacheability.NoCache);                    
                Response.AddHeader("content-disposition", "attachment;filename=" + dr[2].ToString());

                Response.BinaryWrite(arrpicture);

                Response.Flush();

                Response.End();

 

            }

            con.Close();

        }

    }

 
 

 

This will provide the image to Image control in Default.aspx page.

 

 

 

 

 

 
 

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor