WCF REST RESTful WCF 2015 WCF REST REST
- Slides: 20
WCF REST (RESTful-служби із використанням WCF) 2015 WCF REST
Приклад REST- вебслужби. WCF-проект Rest. Service WCF REST 4
Проект Rest. Service. Модуль з інтерфейсом (контрактом) IRest. Service. Impl namespace Rest. Service { [Service. Contract] public interface IRest. Service. Impl { [Operation. Contract] [Web. Get(Response. Format = Web. Message. Format. Xml, Body. Style = Web. Message. Body. Style. Wrapped, Uri. Template = "xml/{id}")] string XMLData(string id); [Operation. Contract] Механізм [Web. Invoke(Method = "GET", URI шаблону Response. Format = Web. Message. Format. Json, (Uri. Template) Body. Style = Web. Message. Body. Style. Wrapped, Uri. Template = "json/{name}")] Contact JSONData(string name); [Operation. Contract] [Web. Invoke(Method = "DELETE", Body. Style = Web. Message. Body. Style. Wrapped, Uri. Template = "del. Contact/{name}")] void contact. Del(string name); } [Data. Contract] public class Contact { [Data. Member] public string name { get; set; } [Data. Member] public string addr { get; set; } WCF REST 5 } IRest. Service. Impl. cs (фрагмент) }
Проект Rest. Service. Модуль Rest. Service. Impl з реалізацією контракта (1/2) public class Rest. Service. Impl : IRest. Service. Impl public string XMLData(string id) return "Hello, " + id; } { { public Contact JSONData(string name) { Contact. List_Singl contact. List = Contact. List_Singl. Get. Contact. List(); Contact c 1; try { c 1 = (from c in contact. List where c. name == name select c). Single(); } catch { c 1 = new Contact { name = "Name not found", addr = "-----" }; } return c 1; } public void contact. Del(string name) { Contact. List_Singl contact. List = Contact. List_Singl. Get. Contact. List(); Contact c 1 = // бажано додати try catch (from c in contact. List where c. name == name select c). Single(); contact. List. Remove(c 1); } WCF REST 6 Rest. Service. Impl. cs (початок фрагменту)
Проект Rest. Service. Модуль Rest. Service. Impl з реалізацією контракта (2/2) public class Contact. List_Singl : List<Contact> { private static Contact. List_Singl contact. List; public static Contact. List_Singl Get. Contact. List() { if (contact. List == null) // "Lazy initialization" { contact. List = new Contact. List_Singl(); Contact c 1 = new Contact { name = "Homa", addr = "Hotiv" }; Contact c 2 = new Contact { name = "Savva", addr = "Sovki" }; contact. List. Add(c 1); contact. List. Add(c 2); }; return contact. List; } } } Rest. Service. Impl. cs (кінець фрагменту) WCF REST 7
Проект Rest. Service. Файл Web. config <? xml version="1. 0"? > <configuration> <system. web> <compilation debug="true" target. Framework="4. 0" /> </system. web> <system. service. Model> <services> <service name="Rest. Service. Impl" behavior. Configuration="Service. Behaviour"> <endpoint address ="" binding="web. Http. Binding" contract="Rest. Service. Impl" behavior. Configuration="web"> </endpoint> • Інфраструктура, що забезпечує зручне використання </service> REST на платформі. NET : </services> –“стандартна” прив'язка – web. Http. Binding; <behaviors> –“стандартна” поведінка (behavior) – web. Http. <service. Behaviors> <behavior name="Service. Behaviour"> <service. Metadata http. Get. Enabled="true"/> <service. Debug include. Exception. Detail. In. Faults="false"/> </behavior> </service. Behaviors> <endpoint. Behaviors> <behavior name="web"> <web. Http/> </behavior> </endpoint. Behaviors> </behaviors> <service. Hosting. Environment multiple. Site. Bindings. Enabled="true" /> </system. service. Model> <system. web. Server> <modules run. All. Managed. Modules. For. All. Requests="true"/> WCF REST 8 </system. web. Server> Rest. Service. Impl. cs (початок фрагменту) </configuration>
Приклад використання служби. Запит HTTP GET. Формат XML Службу запущено на IIS Express IRest. Service. Impl. cs (фрагмент) [Operation. Contract] [Web. Get(Response. Format = Web. Message. Format. Xml, Body. Style = Web. Message. Body. Style. Wrapped, Uri. Template = "xml/{id}")] string XMLData(string id); Rest. Service. Impl. cs (фрагмент) public string XMLData(string id) { return "Hello, " + id; } WCF REST 9
Приклад використання служби. Запит HTTP GET. Формат Json [Operation. Contract] [Web. Invoke(Method = "GET", Response. Format = Web. Message. Format. Json, Body. Style = Web. Message. Body. Style. Wrapped, Uri. Template = "json/{name}")] Contact JSONData(string name); public Contact JSONData(string name) { Contact. List_Singl contact. List = Contact. List_Singl. Get. Contact. List(); Contact c 1; try { c 1 = (from c in contact. List where c. name == name select c). Single(); } catch { c 1 = new Contact { name = "Name not found", addr = "-----" }; } WCF REST 10 return c 1; }
Body. Style = Web. Message. Body. Style. Wrapped <---> Body. Style = Web. Message. Body. Style. Bare [Operation. Contract] [Web. Invoke(Method = "GET", Response. Format = Web. Message. Format. Json, Body. Style = Web. Message. Body. Style. Bare, Uri. Template = "json/{name}")] Contact JSONData(string name); Body. Style = Web. Message. Body. Style. Wrapped WCF REST 11
Приклад використання служби. Запит HTTP DELETE [Operation. Contract] [Web. Invoke(Method = "DELETE", Body. Style = Web. Message. Body. Style. Wrapped, Uri. Template = "del. Contact/{name}")] void contact. Del(string name); WCF REST 12
Додаток 1 WCF REST 15
WCF REST 16
WCF REST 17
WCF REST 18
WCF REST 19
WCF REST 20
- Generally restful like the horizon
- Generally restful like the
- Restful vs restless
- The way my mother speaks carol ann duffy annotated
- Ingredients of art
- Object at rest stays at rest
- Direct retainer in rpd
- Ghost cries purgatorium
- Cingulum rest seat
- Positive rest seat
- Skierkowski
- Golf croquet rules 2019
- Windows communication foundation wcf performance
- Wcfover
- Wcf mutual insurance company
- Wcf ria services
- Wcf rules of golf croquet
- Wcf load balancing
- 2015 vista higher learning inc
- Geschichte abitur 2015 aufgaben
- Management review iso 9001 version 2015 muster