找不到WCF REST Webinvoke

时间:2011-04-25 12:37:52

标签: .net wcf rest .net-4.0 webinvoke

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

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 个答案:

答案 0 :(得分:37)

WebInvokeAttribute位于单独的程序集System.ServiceModel.Web.dll中。你参考那个集会了吗?您还必须添加using System.ServiceModel.Web;

编辑:

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