在WCF服务中清空HttpContext.Current.Request.Files

时间:2011-11-09 12:35:03

标签: wcf html5 file-upload wcf-data-services httpcontext

我正在尝试将文件从html5页面上传到WCF服务,但Files中的HttpContext.Current.Request对象为空。

任何想法?

我的WCF服务:

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class FileUploader
{
    // test file uploader
    [OperationContract]
    [WebGet]
    public string UploadFile()
    {
        string fileName = "no file selected";

        HttpContext context = HttpContext.Current;
        if (context != null)
        {
            if (context.Request.Files.Count > 0)
            {
                fileName = context.Request.Files[0].FileName;
            }
        }

        return fileName;
    }
}

调用javascript是:

function UploadFile() {

    FileUploader.UploadFile(HandleUploadResponse);
}

由于

0 个答案:

没有答案