2011-04-25 37 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

相關問題