【发布时间】:2011-07-30 22:13:28
【问题描述】:
我正在尝试将图像作为附件上传到 REST WCF 服务中,但出现以下错误。 “访问路径“C:\ImageUpload”被拒绝” 我已启用对此文件夹的完全控制权限。我不明白为什么会收到此错误。 我是 WCF 新手,大部分代码都是从在线资源中收集的。 如果我的代码有任何错误,请告诉我。 这是我的代码。
REST WCF Service Code:
[OperationContract]
[WebInvoke(UriTemplate = "uploadImage/{parameter1}")]
void uploadImage(Stream fileStream);
public void uploadImage(Stream fileStream)
{
string filePath = @"C:\ImageUpload";
FileStream filetoUpload = new FileStream(filePath, FileMode.Create);
byte[] byteArray = new byte[10000];
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = fileStream.Read(byteArray, 0, byteArray.Length);
totalBytesRead += bytesRead;
}
while (bytesRead > 0);
filetoUpload.Write(byteArray, 0, byteArray.Length);
filetoUpload.Close();
filetoUpload.Dispose();
}
这是我的测试客户端代码(简单的 .aspx 网页)
protected void btnUpload_Click(object sender, EventArgs e)
{
string file = FileUpload1.FileName;
RESTService1Client client = new RESTService1Client();
byte[] bytearray = null;
string name = "";
if (FileUpload1.HasFile)
{
name = FileUpload1.FileName;
Stream stream = FileUpload1.FileContent;
stream.Seek(0, SeekOrigin.Begin);
bytearray = new byte[stream.Length];
int count = 0;
while (count < stream.Length)
{
bytearray[count++] = Convert.ToByte(stream.ReadByte());
}
}
WebClient wclient = new WebClient();
wclient.Headers.Add("Content-Type", "image/jpeg");
client.uploadImage(FileUpload1.FileContent);
}
【问题讨论】:
-
您向哪个用户授予了完全控制权限?您确定 WCF 服务正在该帐户下运行吗?
-
WCF 服务和客户端都位于我的本地系统上。我授予了我在“ImageUpload”文件夹的安全选项卡下找到的所有用户的完全访问权限。
-
尝试授予“所有人”的访问权限`
-
我尝试授予“所有人”的访问权限。还是不行。
-
关于这个家伙的任何更新。谢谢