WCF REST Webinvoke未找到。

17

以下是我在测试应用程序中使用的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.IO;

namespace MyWCFServices
{
    [ServiceContract]
    interface IHelloWorldService
    {
        [OperationContract]
        String GetMessage(String name);

        //[OperationContract]
        //[WebInvoke(Method = "PUT",UriTemplate = "File/{fileName}")]
        //[WebContentType("application/octet-stream")]
        // bool UploadFile(string fileName, Stream fileContents); 
        [OperationContract]
        [WebInvoke(UriTemplate = "UploadFile/{fileName}")]
        void UploadFile(string fileName, Stream fileContent); 
    }
}

在 webinvoke 编译时出现错误。对此有任何想法吗?

1个回答

38

WebInvokeAttribute 是一个单独的程序集,位于 System.ServiceModel.Web.dll 中。你是否已经引用了该程序集?同时你还需要添加 using System.ServiceModel.Web;

注意:要使用 System.ServiceModel.Web.dll 程序集,你必须至少使用 .NET 3.5 版本,不能使用 .NET 4.0 客户端配置文件。


你正在使用哪个版本的.NET/WCF? - Ladislav Mrnka
我正在使用 .NET 4.0(不是 4.0 客户端框架)。 - Ankit
我从来没有听说过WebContentType属性,据我所知它不是WCF的一部分。 - Ladislav Mrnka
不知何故,ReSharper无法自动添加引用。 - Higgs
@Rohit,解决方案是什么? - Malcolm Salvador
显示剩余6条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接