找不到WCF REST Webinvoke

Ank*_*kit 17 .net rest wcf webinvoke .net-4.0

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

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); 
    }
}
Run Code Online (Sandbox Code Playgroud)

它为webinvoke的编译提供了错误.有什么想法吗?

Lad*_*nka 37

WebInvokeAttribute是在单独的程序集System.ServiceModel.Web.dll中.你参考那个集会了吗?你也必须添加using System.ServiceModel.Web;

编辑:

若要使用System.ServiceModel.Web.dll程序集,必须至少使用.NET 3.5,并且不能使用.NET 4.0 Client Profile.