无法通过Web服务将数据库从数据库写入本地磁盘 [英] Could not write image from Database to local disk through web service

查看:96
本文介绍了无法通过Web服务将数据库从数据库写入本地磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用C#windows应用程序通过Web服务下载客户数据(名称,地址,图像(数据类型是数据库中的图像))。我将字符串(Web服务方法)返回给用户界面。问题是,Image在写入后没有显示(显示跨公园)。以下是

Webservice端和用户界面中的代码。如何解决这个问题。在此先感谢。



WEBSERVICE:



[WebMethod(Description =下载客户)]

[SoapHeader(DeviceDetail,Direction = SoapHeaderDirection.In)]

公共字符串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();

DSCustome rs.WriteXml(sw);

strCustomers = sw.ToString();





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

返回strCustomers;



}

返回strCustomers;

}



catch(SoapException ex)

{

throw ex;

返回strCustomers;

}



用户端代码:



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();
                               }
                               // EncriptMiaFiles(sCustFolderName, sCustId);
                           }










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;
      }

推荐答案

您应该从Web服务发送文件数据作为字节字节的数组[] 而不是像下一篇文章中那样使用XML:

使用Web服务下载文件 [ ^ ]
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[^]


这篇关于无法通过Web服务将数据库从数据库写入本地磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆