WCF 第十三章 可编程站点 使用WebGet和WebInvoke
生活随笔
收集整理的這篇文章主要介紹了
WCF 第十三章 可编程站点 使用WebGet和WebInvoke
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
服務可以使用WebHttpBinding以及WebGet或者WebInvoke屬性來暴露。這些屬性每一個都確定HTTP動作、消息格式以及需要暴露給一個操作的消息體形式。我們將檢查這些屬性的每一個并給出使用每個的原因。
WebGet
WebGet屬性使用GET動詞暴露操作。GET相對于其他HTTP動作有重要的優勢。首先,通過在一個瀏覽器地址欄中輸入服務URI可以直接地訪問終結點。參數可以作為查詢字符串或者編碼字符串在URI中發送。其次,客戶端以及其他下游系統比如代理服務器可以很容易地基于緩存策略來為服務緩存資源。由于緩存能力,WebGet屬性應該只用來做收集用。
? 列表13.6 顯示了使用WebGet和WebInvoke屬性定義的一個服務。WebGet屬性用來收集客戶信息。WebInvoke屬性被用于那些修改數據的添加或者刪除客戶信息的操作。最后,在WebGet和WebInvoke屬性上定義UriTemplate屬性來使用URI定義一個自定義資源。
列表13.6 CustomerService
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; using System.ServiceModel.Web;namespace EssentialWCF {[ServiceContract]public class CustomerService{[OperationContract][WebGet(UriTemplate = "/customer/{id}")]public Customer GetCustomer(int id){Customer customer = null;//Get customer from databasereturn customer;}[OperationContract][WebInvoke(Method="PUT", UriTemplate="/customer/{id}")]public void PutCustomer(int id, Customer customer){//Put customer in database}[OperationContract][WebInvoke(Method="Delete", UriTemplate="/customer/{id}")]public void DeleteCustomer(int id){//Put customer in database}} }
轉載于:https://www.cnblogs.com/danielWise/archive/2011/06/07/2073999.html
總結
以上是生活随笔為你收集整理的WCF 第十三章 可编程站点 使用WebGet和WebInvoke的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: asterisk 操作mysql
- 下一篇: 在 C# 中,new 关键字可用作运算符