1 / 34

Giới thiệu Windows Communication Foundation

Giới thiệu Windows Communication Foundation. Nguyễn Bá Quang. [basquang@hotmail.com] Microsoft Corporation. Nội dung . Windows Communication Foundation là gì ? Kiến trúc hướng dịch vụ (SOA) và WCF Làm gì để xây dựng một ứng dụng WCF? Một dịch vụ WCF hoạt động như thế nào ?

juro
Download Presentation

Giới thiệu Windows Communication Foundation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Giớithiệu Windows Communication Foundation Nguyễn Bá Quang [basquang@hotmail.com] Microsoft Corporation

  2. Nội dung • Windows Communication Foundation làgì? • Kiếntrúchướngdịchvụ (SOA) và WCF • Làmgìđểxâydựngmộtứngdụng WCF? • Mộtdịchvụ WCF hoạtđộngnhưthếnào? • Hosting mộtdịchvụ WCF

  3. Vấnđềphátsinh • Cácphầnmềmhiện nay yêucầukhảnăngtíchhợpcao • … Xâydựngcáchệthốngcótínhkếtnốilàrấtkhó! • Córấtnhiềucôngnghệgiảiquyếtcho • vấnđềtruyềnthôngvàtíchhợphiện nay •  Chọncáinào? • 2. Nhucầuthayđổinềntảngứngdụng • xảyrabấtcứlúcnào •  Làmsaođểchuyểnđổimàtiếtkiệm chi phí

  4. Windows Communication Foundation Khungthốngnhấtchoviệcpháttriểnnhanhcácứngdụnghướngdịchvụ.

  5. Lậptrìnhnềnthuộctính Lậptrìnhnềnthôngđiệp Windows Communication Foundation Ent Services Sys.Messaging Môhìnhthốngnhấtthaythếchocáccôngnghệphântántrướcđó ASMX Remoting Dịchvụ Web ASP.NET Môhìnhtừxa ES/COM+ MSMQ WSE Dịchvụ Web nângcao

  6. Mụctiêuthiếtkế WCF • “Môhìnhlậptrìnhthốngnhấtnhằmpháttriểnnhanhcácứngdụnghướngdịchvụtrênnền Windows” • Thốngnhấtvềcôngnghệ • Giữ nguyênưuđiểm • Thíchhợpchonhiều • mụcđíchsửdụng • Làmộtmôhìnhlậptrìnhhướngdịchvụ • Đápứng 4 tiêuchícủalậptrìnhhướng • dịchvụ • Tươngtácvàtíchhợp • vớicácứngdụngtrên • cácnềntảngkhác • Tươngtácvànângcấp • cácứngdụngphântán • hiệncó

  7. SOA và WCF WCF đãđượcthiếtkếvớicácnguyênlýsaucủa SOA Rõràngvềranhgiới Cácứngdụngvàdịchvụliênlạcvớinhauthông qua cácthôngđiệpmàkhôngquantâmđếnviệcxửlývàtiếpnhận Dịchvụvàsửdụngdịchvụlàđộclậpvớicácquátrìnhnângcấpphiênbản, triểnkhai, hoạtđộngvàbảomật. Tựpháttriển Cácdịchvụcungcấpcácphéptoánvàcấutrúcthông tin. Khôngbaogồmnội dung thông tin Chiasẻyêucầu, khôngchiasẻnội dung Tươngthíchdựatrênchínhsách Cácdịchvụcóthểthiếtkếđểđộclậpvớiviệctriểnkhai, thốngnhấtvớicácứngdụngvềchuẩngiaotiếp

  8. Cáclợiíchcủa SOA Dễdàngthựthi Độclậptriểnkhai, pháttriểnvàquảnlý Nângcaokhảnăngtáisửdụngcôngnghệ Giảm chi phíchoviệccập nhậtvàbảotrìphầnmềm

  9. Xâydựngmộtứngdụng WCF Xâydựngmộtdịchvụ WCF Xâydựngmộtứngdụng client sửdụngdịchvụ WCF

  10. Xâydựngdịchvụ WCF • Địnhnghĩacác Contracts • Data Contract • Operation Contract • Thihànhcácdịchvụ • Cấuhình, triểnkhaivàkiểmthửcácdịchvụ • Cấuhình services trong configuration file • Triểnkhailên IIS 7 • Kiểmthử

  11. Data Contract • [DataContract]: chobiếtmột class đượckhaibáocóthểđượcserialized vàdeserializednhưmột XML stream bởi WCF • [DataMember]: chobiết • thuộctínhnàosẽđược • serialized vàdeserialized

  12. Service Contract • [ServiceContract]: chobiếtmột interface làmột service contract. WCF dựavàothuộctínhnàyđểsinhra metadata cho client khisửdụng • [OperationContract]: chobiếtphươngthứcnàosẽđượcđưavàosửdụng

  13. Thihànhcácdịchvụ • Một class đượccungcấpbởimộtdịchvụ WCF phảithựcthiđầyđủmột service contract.

  14. Cấuhìnhcácdịchvụ WCF • ProductService.svc • Web.config • <serviceModel>: chứathông tin cấuhìnhchomộtdịchvụ Web WCF • <services>: chứathông tin chi tiếtcủamỗi service đượcthựcthi • <service>: chỉra namespace và class màthựcthi service • <endpoint>: cungcấpthông tin chi tiếtcủa service màcácứngdụng client yêucầutheothứtựđểliênlạcvới service • <behavior >: chophép metadata đượccôngbốtới client

  15. Triểnkhaitrên IIS 7 (Vista)

  16. Kiểmthử

  17. Xâydựngứngdụng client

  18. Nguyênlý ABCs của WCF

  19. C C C B B B A A A Kiếntrúc ABCs của WCF Service Host Client Service Bv Bv Message Bv Bv Address Binding Contract (Where) (How) (What) Endpoint

  20. Endpoints • Address: Where? • Chỉ ranơinàođểgửivànhậnthôngđiệp • Chỉ ra nơi nàođểtìmra Endpoints • Binding: How? • Chỉ ralàmcáchnàođểgửithông điệp • Chỉ ra làm sao để client liên lạc với Service endpoints • Contract: What? • Chỉ ranhưngcáigìđượcbaogồmtrongthông điệp • Chỉ ra những dịch vụ nào client có thể sử dụng • Behaviours: • Triển khai chi tiết

  21. Address • Nơiđểtruyềnvànhậnthôngđiệp • Cungcấpthông tin: • Đườngdẫn • Giaothứcvậnchuyển • Tên Host • Cổngtruycập [transport]://[machine][:optional port] http://localhost http://localhost:8081 http://localhost:8081/Service net.tcp://localhost:8082/Service net.pipe://localhost/Pipe

  22. Address URI Scheme Host Port Path Chiasẻ Port thông qua TCP Port Sharing Service Peer to Peer Named Pipes MSMQ TCP HTTP net.p2p://localhost/MyServiceNetPeerTcpBinding net.pipe://localhost/MyService NetNamedPipeBinding net.msmq://localhost/private/MyService NetMsmqBinding net.tcp://localhost:8088/MyService NetTcpBinding http://localhost:80/MyServiceBasicHttpBindingWSHttpBindingWSDualHttpBindingWSFederationHttpBinding Chiasẻ Port thông qua HTTP.SYS

  23. Bindings (Gắnkết) • Môtảcách Client kếtnốivới services • Địnhdạngdữliệumongmuốn • Cóthểbaogồmcácthông tin • Giaothứcvậnchuyển • Địnhdạngmãhóathôngđiệp • Cơchếbảomật • Cơchếgiaodịch • Tính tin cậytrongliênlạc Mộtsố bindings phổbiến BasicHttpBinding NetTcpBinding WSHttpBinding NetMsqmqBinding

  24. Contracts (Hợpđồng) • [Service Contract]: Làmột Interface • [OperationContract]: Môtảcácphéptoáncóthểthựcthibởi service • Toànbộ data phảiđượcserializable • [Data Contract]: Môtảcấutrúcdữliệuvàcáchmàdữliệuđượcserializable.

  25. Hosting and Demo IIS 7 và WAS Windows Service Ứngdụng User

  26. Hosting: Ứngdụngngườidùng class HelloHost { static void Main(string[] args) { ServiceHosthost = new ServiceHost(typeof(HelloService)); host.Open(); Console.ReadLine(); host.Close(); } } <service name="HelloService">  <host>    <baseAddresses>      <add baseAddress="http://localhost:8000"/>    </baseAddresses>  </host> … </service>

  27. Hosting: Ứngdụngngườidùng • Thuậnlợi • Kiểmsoáttoànvẹn • Khônggiớihạntrongviệc binding/behavior • Sửdụngcácứngdụngcógiaodiện • Khókhăn • Khôngcócácchứcnăngquảnlý Hosting

  28. Hosting: Windows Service public class WindowsService : ServiceBase { ServiceHost host; protected override void OnStart(string[] args) { host = new ServiceHost(typeof(HelloService)); host.Open(); } protected override void OnStop() { host.Close(); } } [RunInstaller(true)] public class WindowsServiceInstaller : Installer { public WindowsServiceInstaller() { ServiceProcessInstaller spi = new ServiceProcessInstaller(); ServiceInstaller si = new ServiceInstaller(); Installers.Add(spi); Installers.Add(si); } }

  29. Hosting: Windows Service • Thuậnlợi • Tựđộng Start/Stop/Restart • Có tool quảnlý service • Cóthểthựcthi ở tàikhoảnmáycũngnhưngườidùng • Khókhăn • Sựkíchhoạtkhôngcóthôngbáo

  30. Hosting: IIS7/WAS <%@ Service language="C#" class="HelloService" %> using System; using System.ServiceModel; public class HelloService : IHelloService { … } http://localhost/HelloService/HelloService.svc

  31. Hosting: IIS7/WAS • Thuậnlợi • Kíchhoạtsẵncótrong IIS • Hỗtrợ Named Pipes, TCP, and MSMQ • Sửdụngcôngcụquảnlý IIS7 mới • Khókhăn • Chỉhoạtđộngtrên VISTA

  32. Tómtắtvề WCF • WCF làcôngnghệchotínhtoánphântán • WCF tíchhợptấtcảcáccôngnghệphântántốtnhất • Sửdụngchuẩn Web Services đểtươngtácvàtíchhợpvớicácgiảiphápđangtồntại • WCF sẵncótrong Windows Vista, Windows XP SP2, Windows Server 2008

  33. Check out the WCF community site for a list of useful resources: http://windowscommunication.net Download and prototype on the WCF CTP Releases: http://msdn.microsoft.com/windowsvista/getthebeta/default.aspx Leverage the community forum to post comments and connect with the feature team: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=118&SiteID=1 Thamkhảothêm….

More Related