Asp.net 如何使用web服务将图像作为附件发送?
我想向web服务添加新员工。 员工照片应作为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
并作为受密码保护的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);
}