Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何使用web服务将图像作为附件发送?_Asp.net_Wcf_Web Services_Sharpziplib - Fatal编程技术网

Asp.net 如何使用web服务将图像作为附件发送?

Asp.net 如何使用web服务将图像作为附件发送?,asp.net,wcf,web-services,sharpziplib,Asp.net,Wcf,Web Services,Sharpziplib,我想向web服务添加新员工。 员工照片应作为web服务的附件发送。 并作为受密码保护的ZIP文件发送。为图像创建一个类并作为流发送,如下所示 您必须为每个图像添加流转换,并将详细信息添加到列表中 在客户端 Stream stream = (Stream)openDialog.File.OpenRead(); byte[] bytes = new byte[stream.Length]; stream.Read(byt

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

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

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

在客户端

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