为什么我在WCF4中上传文件时遇到这么多麻烦?

时间:2011-03-20 20:39:35

标签: wcf wcf-data-services

这让我困扰了4个多小时。我无法在任何地方找到一个简单的例子?

我的网络应用程序有一个WCF数据服务,我希望能够将图像上传到自定义操作。

或者我有WCF REST模板服务,它只有.cs,NO .config和NO .svc文件。它在global.asax中有一条路线

        // Edit the base address of Service1 by replacing the "Service1" string below
        RouteTable.Routes.Add(new ServiceRoute("upload", new WebServiceHostFactory(), typeof(UploadService)));

我的操作如下:

    [WebInvoke(Method ="POST", UriTemplate = "update-pic/{id}")]
    public Message UploadPic(string id, Stream fileContents)
    {

        System.Drawing.Image.FromStream(fileContents).Save(string.Format("{0:ddmmss}.jpg"));

        return WebOperationContext.Current.CreateTextResponse("Success: " + id);
    }

但无论我在客户端做什么,当我致电该服务时,我得到400响应。我可能遇到消息大小限制的问题,但我不知道如何使用WCF RestTemplate样式进行配置。

如果我没有将任何内容设置为响应流,那么我设法点击该服务。

是否有人为WCF4提供端到端服务和客户端示例 - 我对3.5不感兴趣

0 个答案:

没有答案
相关问题