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:
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();
}
}
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;
}