当我添加我的 WebService 时,我开始收到所有这些错误:
'Stream' 是 'System.IO.Stream' 和 'MultiSelectFileUploader.ServiceReference.Stream' 之间的模糊引用
当我所拥有的只是 GetFiles() 时,这并没有发生。我可以继续将我的 Streams 更改为 System.IO.Stream,但是当我尝试传递给 UploadFiles() 时,我得到它不是 ServiceReference.Stream 的错误。感谢您的帮助。
这是我的网络服务...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
namespace MultiSelectFileUploader.Web
{
/// <summary>
/// Summary description for FileService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class FileService : System.Web.Services.WebService
{
[WebMethod]
public List<string> GetFiles()
{
List<string> l = new List<string>();
foreach (FileInfo fi in (new DirectoryInfo(Server.MapPath("~/Temp/")).GetFiles()))
l.Add(fi.Name);
return l;
}
[WebMethod]
public void UploadFiles(string filename, Stream file)
{
string filepath = AppDomain.CurrentDomain.BaseDirectory + @"Temp\";
if (!Directory.Exists(filepath)) { Directory.CreateDirectory(filepath); }
WriteFile(file, File.Create(Context.Server.MapPath("~/Temp/" + filename)));
}
private void WriteFile(Stream stream, FileStream fs)
{
int bytesRead;
byte[] buffer = new byte[4096];
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
fs.Write(buffer, 0, bytesRead);
}
}
}