當我加我的WebService我開始所有這些錯誤:向Silverlight(3.0)添加WebService時模糊引用?
「流」是「System.IO.Stream」和「MultiSelectFileUploader.ServiceReference.Stream」
這WASN」之間不明確的引用當我在那裏的時候發生了GetFiles()。我可以繼續並將Streams更改爲System.IO.Stream,但是當我嘗試傳遞給UploadFiles()時,出現錯誤,它不是ServiceReference.Stream。感謝你的幫助。
這裏是我的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);
}
}
}
你有你自己的Stream類嗎? –
不,呃,不是故意的。在我的xaml.cs中,我可以做ServiceReference.Stream,但我自己並沒有這樣做。 (我想不知怎麼它放到了那裏,因爲我在傳遞給UploadFiles()的參數中引用了Stream)。 – Ber53rker