320 likes | 462 Views
Windows Communication Foundation. a.k.a >>>>>>(WCF - Indigo)<<<<<. Instructor: Mr. Phạm Thi Vương. Students: Đỗ Hồng Hải Đỗ Trường Giang Trần Công Vương. Tổng quan. Introduction Web Service – Oriented Review WCF Fundamentals How to set up WCF Web Service Reference Q&A. Section .
E N D
Windows Communication Foundation a.k.a >>>>>>(WCF - Indigo)<<<<< Instructor: Mr. PhạmThiVương Students: ĐỗHồngHải ĐỗTrườngGiang TrầnCôngVương
Tổngquan • Introduction • Web Service – Oriented • Review WCF Fundamentals • How to set up WCF Web Service • Reference • Q&A
Section Introduction
Đôinétvề WCF • Nềntảng “Communication” giữacácứngdụng • Làmộtphầntrong.Net Framework • Hoạtđộng qua Internet hoặc inter-process
a bit of history Object-oriented 1980s Polymorphism Encapsulation Sub-classing Component-oriented 1990s Location Transparent Tight Coupling Runtime Metadata Service-oriented 2000s Message-based Schema+Contract+Policy Broad Interop
[ServiceContract] class HelloService { [OperationContract] [PrincipalPermission(SecurityAction.Demand, Role = “Adminstrators")] [TransactionFlow(TransactionFlowOption.Mandatory)] [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)] String Hello(String Greeting) {return Greeting;} } <bindings> <wsHttpBinding> <binding name="Binding1“ transactionFlow="true"> <security mode="Message"> <message clientCredentialType="Windows“/> </security> <reliableSession enabled="true" /> </binding> </wsHttpBinding> </bindings> • class HelloService { • [WebMethod] • public String Hello(String Greeting) { • X509CertificateCollection collection = new X509CertificateCollection(); • IntPtr blob = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CRYPTOAPI_BLOB))); • IntPtr data = (IntPtr)((int)blob + • Marshal.SizeOf(typeof(CRYPTOAPI_BLOB))); • … • SeqAckRange range = new SeqAcknRange(id, low, high ); • SeqAckRange[] ranges = { range }; • ReliableQueue.ProcessAcks( ranges ); • … • BeginTransaction (NULL, • ISOLATIONLEVEL_SERIALIZABLE, 0, pITxOptions, • &pITransaction); • … • return Greeting; • } • } class HelloService { [WebMethod] public String Hello(String Greeting) { foreach ( SecurityToken tok in requestContext.Security.Tokens { X509SecurityToken token = tok as X509SecToken } … SeqAckRange range = new SeqAcknRange(id,low,high ); SeqAckRange[] ranges = { range }; ReliableQueue.ProcessAcks( ranges ); … BeginTransaction (NULL, ISOLATIONLEVEL_SERIALIZABLE, 0, pITxOptions, &pITransaction); … return Greeting; } } 20,379 linessecurity 10 lines security 1 code + 2 config (elem.) security 1,804 lines reliable messaging 5,988 lines reliable messaging 0 code + 1 config (elem.) reliable messaging 25,507 linestransactions 25,507 linestransactions 2 code + 1 config (attr.)transactions Total lines 27,321 4,442 lines infrastructure Total lines:3 code (what) + 4 config (how) Total lines 56,296 efficient
Mộtsốđặcđiểmchính • Thốngnhấtphươngthứctraođổithông tin trênnềntảng .NET • Cóthểđượctriểnkhaitrêncácnềntảngkhác • Cóthểsửdụng qua internet, mạng LAN hay giữacác process • Thíchhợpđểpháttriểncácứngdụngphântán • Dễdàngứngdụng, bảotrì, nângcấptrongpháttriểnphầnmềm • Tíchhợpchặtchẽvớicácứngdụngkháctrêncùngnềntảng • Cókhảnăngtựtíchhợpdạngđệquy hay vớicácwebservicekhác • HỗtrợrộngrãicácđặctảpháttriểnWebservice Unified Service Intergration
Section Web service - Oriented
Service-Oriented Requirement Application bắtbuộc State baogồm quảnlý quảnlýbằng Policy Service traođổi giớihạnnhờ Message Exchange Pattern có baogồm Message môtả Contract địnhnghĩa tạonêntừ Schema
Message Message Service Communication Client Service
Endpoint Endpoint Endpoint Endpoints Client Service Message
C C C B B B A A A Address, Binding, Contract Client Service Message Address Binding Contract (Where) (How) (What)
C C C B B B A A A Behaviors Metadata Caller Service Bv Bv Message Bv Bv Address Binding Contract (Where) (How) (What)
C C C B B B A A A Runtime Metadata Client Service Bv Bv Message Bv Bv ServiceHost Proxy Address Binding Contract (Where) (How) (What)
Section Review WCF Fundamentals
address • Thông tin địnhdanhcủa Service • Chỉcómột address duynhấtchomột service
contract • Đơngiảnhóaviệcđặctảcác message vàcôngđoạngửi – nhận • Gồmcácloại: • Service Contract • Operation Contract • Data Contract • Fault Contract • Message Contract
contract • Chứacác operation • Tươngtựnhưmột interface • Chỉrõwebservicesẽtraođổinhữnggì • Serialize WSDL:portType Operation
data contract Wsdl:message • Mộttổhợpđịnhnghĩanhằmthốngnhấtkiểudữliệugiữa server/client • Cóthểthaybằngcáclớpdữliệukhác Wsdl:part Xsd:element
Message Exchange pattern • Đặctảphươngthứctruyềnthông tin • Gồm 3 loại: • Request-reply • One-way (datagram) • Duplex (callback)
behavior • Nằmtrongphạm vi của contract • Mởrộng hay tùybiếncáctínhnăngcủa service • Thamgiavàoquátrìnhkhởitạocác channel
binding • Đặctảkếtnốicủa endpoint • BaogồmnhiềubindingElement – nhiềucáchkếtnốivớiclient
Hosting WCF • IIS • Self-Hosting trongcácứngdụngnền .NET • Console Application • Windows Form • Windows Service • Windows Activation Service (WAS)
Section Demo WCF Web service
set up web service • Thêmreference ServiceModeltrong project – import • TạoServiceContract • ĐịnhnghĩacácOperationContract • Implement interface
set up web service (2) • Done? • Not so fast! • Để Client cóthểkếtnốiđến endpoint, web service cầnkhaibáothêm Metadata
client Add reference Code
Section Reference
Reference Resources • MSDN • CodeProject • Introducing Windows Communication Foundation – Microsoft • Best friend: Google
Caution!!! Q&A