2011-04-25 69 views
14

以下是我用我的测试应用程序的代码:WCF REST 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。任何想法都一样?

回答

34

WebInvokeAttribute在单独的程序集System.ServiceModel.Web.dll中。你是否参考过这个程序集?你还必须添加using System.ServiceModel.Web;

编辑:

要使用System.ServiceModel.Web.dll组件您必须至少使用.NET 3.5,您不能使用.NET 4.0客户端配置文件。

+0

WebContentType怎么样? – Ankit 2011-04-25 12:41:55

+0

您使用的是什么版本的.NET/WCF? – 2011-04-25 12:42:57

+0

我正在使用.NET 4.0(不是4.0客户端配置文件) – Ankit 2011-04-25 12:57:35