發表文章

目前顯示的是有「WCF」標籤的文章

如何讓Restful Service回應圖片

在一般利用WCF還做restful的服務,回應的部分可以指定要輸出為XML格式或是JSON格式,那麼如果說想要直接回應一張圖片的時候應該要怎麼進行呢? 手上是用WPF的應用程式,先Self Host一個restful service上去,之後來處理回應圖片的部分,下面是參考資訊來源 Self host http://stackoverflow.com/questions/20805317/how-to-set-up-wcf-self-hosted-rest-service Response image http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/fetching-image-using-wcf-rest-service/ http://stackoverflow.com/questions/12781173/cant-return-image-from-wcf-rest-service 主要的方式便是將圖片轉換成Stream,之後http這邊設定回應的類型是image,這樣就可以達成想要的樣子了,下面來看看程式碼的部分吧 Interface     [ ServiceContract ] interface   IMyService {     [ OperationContract ]     [ WebInvoke (UriTemplate  =   "/GetImage" , Method  =   "GET" ,         RequestFormat  =   WebMessageFormat . Xml, ResponseFormat  =   WebMessageFormat . Xml,         BodyStyle  =   WebMessage...

WCF服務中如何同時啟用SOAP與REST兩種類型的服務端點

在WCF服務中,除了原先SOAP的服務外,我們也可以建立REST的服務類型,那如果說要在同一支服務當中,同時建立兩種的話應該要怎麼做呢?這邊先簡單筆記一下,之後有時間再來補齊 主要的方式就是要建立兩個EndPoint,一個給SOAP用,一個給REST用;而Interface的部分也要建立兩份,比如說REST的介面像是下面這樣     [ ServiceContract ]      public   interface   IRestfulService     {         #region  Member query         [ OperationContract ()]         [ WebGet ( UriTemplate   =   "/Members/Query/MemberId/{memberId}" ,  ResponseFormat   =   WebMessageFormat . Json ,  BodyStyle   =   WebMessageBodyStyle . Wrapped )]          Data . Member   restGetMemberByMemberId ( string   memberId );         [ OperationContract ()]         [ WebGet ( UriTemplate   =  ...