Wcf WebInvoke 與WebGet 的區別!


WebInvoke與 WebGet 作用都是為了把當前服務給暴露出去,允許客戶端直接調用此服務, WebInvoke 更適用於對數據進行操作(數據錄入,數據修改,數據刪除),WebGet 的定義提交方式類似 "Get" 所以更適用於數據查詢(數據呈現),

using System.ServiceModel;
using System.ServiceModel.Web
共同的引用。他們屬性是一樣的
    BodyStyle                          獲取和設置傳入與傳出服務操作的消息的正文樣式。

IsBodyStyleSetExplicitly 獲取 IsBodyStyleSetExplicitly 屬性

IsRequestFormatSetExplicitly 獲取 IsRequestFormatSetExplicitly 屬性。
IsResponseFormatSetExplicitly 獲取 IsResponseFormatSetExplicitly 屬性。
Method 獲取和設置服務操作響應的協議(如 HTTP)方法。
RequestFormat 獲取和設置 RequestFormat 屬性。
ResponseFormat 獲取和設置 ResponseFormat 屬性。
TypeId 在派生類中實現時,獲取此 Attribute 的唯一標識符。(繼承自 Attribute。)
UriTemplate 用於服務操作的統一資源標識符 (URI) 模板。
加上這兩個我認為就是  REST 和Wcf  就有點遠了,但都同是 Service
 
代碼:
        [OperationContract]
        [WebGet(UriTemplate = "/Action/{id}" )]   //可以直接根據具體的參數 id進行訪問
                    
        public string  Get ( int id)
        {
           String str=" Hellow Word";
                              str+=id;
            return str;
        }
 
 
             [OperationContract]
             [WebInvoke(Method = "POST", UriTemplate = "UpdateBasicData", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
             int UpdateBasicData(SysBasicData model);
 
 
剛剛學習,請各位大神指點!

 

  名稱 說明
System_CAPS_pubproperty BodyStyle

獲取和設置傳入與傳出服務操作的消息的正文樣式。

System_CAPS_pubproperty IsBodyStyleSetExplicitly

獲取 IsBodyStyleSetExplicitly 屬性。

System_CAPS_pubproperty IsRequestFormatSetExplicitly

獲取 IsRequestFormatSetExplicitly 屬性。

System_CAPS_pubproperty IsResponseFormatSetExplicitly
System_CAPS_pubproperty Method

獲取和設置服務操作響應的協議(如 HTTP)方法。

System_CAPS_pubproperty RequestFormat

獲取和設置 RequestFormat 屬性。

System_CAPS_pubproperty ResponseFormat

獲取和設置 ResponseFormat 屬性。

System_CAPS_pubproperty TypeId

在派生類中實現時,獲取此 Attribute 的唯一標識符。(繼承自 Attribute。)

System_CAPS_pubproperty UriTemplate

用於服務操作的統一資源標識符 (URI) 模板。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM