2010-11-16 53 views
7

什麼時候應該使用post vs get?在WCF上的REST服務中,下面是我的接口WIn上的REST服務的WebInvoke Method =「POST」或「GET」

 [OperationContract] 
     [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] 
     string DoLodge(string Id, Lodge value); 

     [OperationContract] 
     [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] 
     LodgeLevel[] GetLodgeLevels(string Id); 

     [OperationContract] 
     [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] 
     long GetLodgeCount(string Id); 

回答

6

POST每次像數據庫更新,刪除。 GET只讀取數據庫選擇。

2

GET:獲取條目(作爲feed文檔)或單個條目(作爲條目文檔)的集合。

POST:從入口文檔創建新條目。

PUT:使用條目文檔更新現有條目。

刪除:刪除條目。

0

但是在C#中,您會收到GET響應。 所以完整答案是 從服務器檢索對象時使用GET,並在從服務器發回更新時使用GET。