【问题标题】:how to send image as attachment with web service?如何通过网络服务将图像作为附件发送?
【发布时间】:2013-01-27 11:31:18
【问题描述】:

我想将新员工添加到 Web 服务。 员工照片应作为 Web 服务的附件发送。 并作为受密码保护的 ZIP 文件发送。

【问题讨论】:

    标签: asp.net wcf web-services sharpziplib


    【解决方案1】:

    为您的图像创建一个类并作为流发送,如下所示,

    您必须为每个图像添加流转换并将详细信息添加到列表中。

    在客户端。

    Stream stream = (Stream)openDialog.File.OpenRead();
                        byte[] bytes = new byte[stream.Length];
                        stream.Read(bytes, 0, (int)stream.Length);
                        BitmapImage bmi = new BitmapImage();
                        using (MemoryStream ms = new MemoryStream(bytes))
                        {
                            bmi.SetSource(ms);
                            newRow.Thumbnail = bmi;
                    }
    

    在您的服务端

    string filePath = ConfigurationManager.AppSettings.Get("ImageUploadPath");
    
                              if (!Directory.Exists(filePath))
                              {
                                  Directory.CreateDirectory(filePath);
                              }
    
                              filePath = filePath + "\\" + picture.FileName + "." + picture.FileType;
    
                              if (picture.FileName != string.Empty)
                              {
                                  fileStream = File.Open(filePath, FileMode.Create);
                                  writer = new BinaryWriter(fileStream);
                                  writer.Write(picture.FileStream);
                              }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-16
      相关资源
      最近更新 更多