Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am downloading customer data( Name , address, Image(data type is image in database)) through web service using C# windows application. I am returning the string (web service method) to user interface.Issue is ,Image is not displaying(displaying cross park) after writing. Below are the codes in
Webservice side and user interface. How to resolve this. Thanks in advance.

WEBSERVICE:

[WebMethod(Description = "Download Customers")]
[SoapHeader("DeviceDetail", Direction = SoapHeaderDirection.In)]
public string CustomerDownload()
{
DataSet DSCustomers = new DataSet();
string strCustomers = "";

try
{
if (DeviceDetail != null)
{

objDevieDataDL = new BL_DeviceDataDownload();
DSCustomers.Tables.Add(objDevieDataDL.GetCustomers(DeviceDetail.DeviceID));
DSCustomers.Tables.Add(objDevieDataDL.GetCustomerIndex(DeviceDetail.DeviceID));

StringWriter sw = new StringWriter();
DSCustomers.WriteXml(sw);
strCustomers = sw.ToString();


//strCustomers = DSCustomers.GetXml().ToString();
return strCustomers;

}
return strCustomers;
}

catch (SoapException ex)
{
throw ex;
return strCustomers;
}

User side Code:

C#
if (drCustDoc.Length != 0)
                      {
                       foreach (DataRow drPhoto in drCustDoc)
                        {
                                   if (drPhoto["Pic"] != null && drPhoto["Pic"].ToString() != "")
                                   {
             
     byte[] bytImage = GetBytes(drPhoto["Pic"].ToString());
                                                                                      sImgFileName = drPhoto["pagename"].ToString();

   if (bytImage.Length > 100)
    {
      FileStream fs1 = new FileStream(sCustFolderName + "\\" + sImgFileName, FileMode.Create);
                                           fs1.Write(bytImage, 0, System.Convert.ToInt32(bytImage.Length));
                                           fs1.Seek(0, SeekOrigin.Begin);
                                           fs1.Close();
                                           fs1.Dispose();
                                       }
                                   }
                                   sCustName = drPhoto["CustomerName"].ToString();
                               }
                               // EncriptMiaFiles(sCustFolderName, sCustId);
                           }



C#
static byte[] GetBytes(string str)
      {
          byte[] bytes = new byte[str.Length * sizeof(char)];
          System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
          return bytes;
      }
Posted
Updated 27-Nov-14 1:17am
v2

1 solution

You should send from your Web Service the file data as array of byte byte [] and not by using XML like is done in the next article:
File Download using Web Service[^]
 
Share this answer
 
Comments
DileepReddyC 1-Dec-14 4:56am    
Thank You Very much
Raul Iloc 2-Dec-14 1:26am    
Welcome, I am glad that I could help you!

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