日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

WCF 第十三章 可编程站点 使用WebGet和WebInvoke

發布時間:2024/10/8 62 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。