When I add my WebService I started getting all these errors:
‘Stream’ is an ambiguous reference between ‘System.IO.Stream’ and ‘MultiSelectFileUploader.ServiceReference.Stream’
This wasn’t happening when all I had in there was the GetFiles(). And I can go ahead and change my Streams to System.IO.Stream, but then I get the error that it isn’t a ServiceReference.Stream when I try to pass to the UploadFiles(). Thanks for the assitance.
Here’s my WebService…
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);
}
}
}
Streaming is not supported in ASMX services. You have to use WCF.