Empty HttpContext.Current.Request.Files in WCF Service

若如初见. 提交于 2019-12-08 03:10:07

问题


I'm trying to upload files form a html5 page to a WCF Service but the Files object in the HttpContext.Current.Request is empty.

Any Idea?

my WCF Service:

[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;
    }
}

The calling javascript is:

function UploadFile() {

    FileUploader.UploadFile(HandleUploadResponse);
}

Thanks

来源:https://stackoverflow.com/questions/8065105/empty-httpcontext-current-request-files-in-wcf-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!