WCF (Windows Communication Foundation) 제대로알기 WCF 등장배경및프로그래밍기초소개 드원테크놀로지 수석컨설턴트 유경상
Agenda Understanding Web Service History of Communication Problem of Legacy Communication Infra Requirement of New Communication Infra Understanding WCF What s WCF? WCF Features Basic Programming Model of WCF Conclusion
UNDERSTANDING WEB SERVICES
Why Web Service? Understanding Background of Web Services Web Service의등장의의를이해할수있음 Web Service를왜사용해야하는가에대한답을찾을수있음 SOA (Service Oriented Architecture) 를이해하는데도움이됨 Web Services의다양한표준에대한이해에도움이됨 WCF의등장배경을이해하는데도움이됨 Communication between Applications 오랫동안어플리케이션사이에통싞방법이변화됨 다양한문제점들을해결하는방향으로발젂 보다편리한개발을위한방향으로발젂 새로운프로토콜, 제품들이등장 가장최근에는 XML Web Service로통합되고있음
History of Communication (1) Stone Age 메인프레임과더미터미널통싞 문자기반의통싞 Age of Down sizing 워크스테이션서버들을이용한분산처리 TCP/IP, Socket 프로그래밍보급 젂문방식메시지통싞 Age of Middleware 메시지처리의자동화 데이터마샬링, 메쏘드디스패치자동화 프로그래밍언어에의졲적 데이터패킷기반미들웨어 : Tuxedo, Tmax,... RPC 기반미들웨어 : Entera,...
History of Communication (2) Age of Distributed Components 프로그래밍언어와무관한통싞방법필요 객체지향적인프로그래밍방식필요 객체지향프로그래밍의한계 컴파일러의졲적, 낮은코드재사용성등 분산컴포넌트등장 Component Based Design (CBD) 다양한분산객체기술 / 프로토콜도입 COM/DCOM, CORBA/IIOP, Java/RMI (Remote Method Invocation) 분산객체기반의미들웨어 COM+ (DCOM) Orbix (IIOP) EJB (RMI)
Problem of Distributed Components Interoperability Problem 내것이네것보다낫다! CORBA, DCOM, RMI 가각각의바이너리포맷을가짐 각표준의벤더들이자싞기술이컴포넌트기술의인프라가되길원함 상호운영성 (interoperability) 이현저히떨어짐 프로그래밍언어장벽 CORBA C/C++ 및 COBOL 등몇몇언어지원 RMI (java) Java 언어만을지원 DCOM C/C++, VB, Delphi, PowerBuilder 등언어지원 인터넷비호홖 분산객체프로토콜들은가변포트사용 다수의클라이언트지원을위해다수의 TCP/IP 포트사용 방화벽을통과하기매우어려움 보안상다수의포트를개방할수없음
Engaging Web Services Request for New Communication Infra 표준준수 국제표준기구에서제정하는국제적 IT 표준을사용할것 상호운영성 / 독립성 특정벤더에종속적이지않으며, 구현기술, 구현언어에독립적일것 다양한운영체제, 개발플랫폼에서모두쉽게지원할수있을것 인터넷적응성 인터넷홖경에적응하기쉬운인터넷기술을사용할것 낮은복잡도 갂단명료하여복잡한처리를요구하지않을것 Web Service Concept 세부구현에관계없이소프트웨어컴포넌트 ( 모듈, 함수 ) 를인터넷상의하나의서비스 ( 기능집합 ) 으로서제공 높은상호운영성을가지며다양한 H/W, 운영체제, 개발플랫폼 상에서서비스를개발하거나클라이언트를개발
SOAP SOAP (Simple Object Access Protocol) 웹서비스에사용하는프로토콜 메시지기반 W3C 표준 : Microsoft, IBM, BEA 등주요벤더들주도 XML 기반이므로다양한플랫폼에서모두지원될수있음 HTTP, SMTP 등인터넷기반프로토콜을하부구조로사용함 갂단하지만확장가능한명세로구성됨 POST /url HTTP/1.1 Host: HostServerName SoapAction: http://banking.sample/deposit <?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <soap:header> <!-- addtional header information --> </soap:header> <soap:body> <Deposit xmlns="http://banking.sample/"> <AccountID>123-45-678-1234</AccountID> <Amount>20.0</Amount> </Deposit> </soap:body> </soap:envelope>
SOAP Message Driven Comm. Client Banking service = new Banking(); SOAP Message <soap:envelope xmlns:soap= > <soap:body> </soap:body> </soap:envelope> Server Service Implementation Call to proxy Web Service Proxy Serialize Method Call into SOAP message ASMX Handler Deserialize from SOAP message Call to Web Method Web Method service.deposit( ); Service Implementation
We Need More Problems of Web Service & SOAP 구현마다조금씩상이한 SOAP 메시지구현 짂보된 SOAP 메시지보안필요 SSL 만으로는라우팅등다양한보안요구사항을만족하기어려움 다양한인증서비스를만족할수있어야함 싞뢰할수있는 SOAP 메시지배달필요 Reliable Messaging Long-running, Loosely-coupled 트랜잭션지원요구 인터넷상에연결된웹서비스들사이의트랜잭션메커니즘필요 웹서비스를통해대용량바이너리데이터통싞필요 이러한새로운요구사항들이상호운영성을해쳐서는안됨 Lack of functionality with SOAP 1.x
New Web Service Standards (1) WS-* Specifications 새로이요구되는다양한기능을위한웹서비스스펙 호홖성관련 : WS-I Profile 메시징관련 : SOAP 1.2, MTOM, WS-Addressing, 보안관련 : WS-Security, WS-Trust, WS-Federation, 트랜잭션관련 : WS-AtomicTransaction, 싞뢰성관련 : WS-ReliableMessaging 메타데이터 (WSDL) 관련 : WSDL, WS-Policy, SOAP 메시지의확장 SOAP 메시지의 Header 요소를통해기능확장 기졲웹서비스근갂을그대로유지 W3C 에의해표준으로유지 ( 혹은일부짂행중 ) 상호운영성 벤더에종속적이지않음 다양한벤더들이지원 ( 모든스펙을지원하는것은아님 ) Microsoft, BEA, IBM,
New Web Service Standards (2)
Communication of Windows World (1) WinSock Windows Socket 라이브러리 TCP/IP 등저수준의네트워킹 WinINet HTTP, FTP 등인터넷프로토콜구현 클라이언트용 RPC Windows 서비스들이다수사용 TCP/IP, Named Pipe, HTTP 등다수 Transport 하부프로토콜사용가능 C/C++ 젂용 DCOM RPC 기반 Windows 운영체제와 COM+ 에서폭넓게사용 MSMQ 비동기메시지젂송및메시지큐기능제공
Communication of Windows World (2) In Managed World System.Net namespace (HTTP, FTP, SMTP, Socket).NET Remoting ASP.NET Web Service WSE 3.0 WS-Addressing, WS-Security, MTOM 등일부 WS-* 스펙지원 ASP.NET Web Service 의에드온성격 Enterprise Services (COM+) MSMQ (System.Messaging) Problems 각기다른프로그래밍모델을가짐 각기다른 configuration 설정을가짐 서비스의구현로직은재사용가능하지만통싞에필요한코드는재사용할수없음
Requirement of New Comm. Infra Service Oriented Architecture 서비스기반아키텍처 Web Service based XML 기반 상호운영성 다양한웹서비스스펙들을지원 메시징, 보안, 트랜잭션, 싞뢰성, 메타데이터등 Unified Programming Model 단일코드로다양한프로토콜, 성능요구사항에대처할수있어야함 HTTP, TCP, MSMQ 등하부프로토콜에관계없이단일코드사용 Compatibility ASP.NET Web Service 등기졲서비스 / 클라이언트와호홖되어야함 Support New Trend P2P communication
Windows Communication Foundation What s WCF? 차세대닷넷 Communication 인프라.NET Framework 3.0 의기능 Service Oriented Architecture 기반 Web Service (XML + SOAP) 기반 다양한 Communication 프로토콜지원 HTTP TCP/IP Named Pipe MSMQ P2P 다양한웹서비스스펙지원 WS-Security WS-AtomicTransaction WS-ReliableMessaging
Why WCF? Future Communication Infra 웹서비스기반 (XML + HTTP) 서비스지향아키텍처 (SOA) Interoperability 표준 WS-* 스펙구현 Next generation communication infra of Microsoft Common Programming Model Web Service,.NET Remoting, LRPC, MSMQ 프로토콜에관계없이하나의프로그래밍모델사용가능 단일코드베이스사용가능 New feature 트랜잭션, 싞뢰할수있는메시징, P2P, 다양한바인딩 ( 프로토콜지원 )
WCF Features Web Service Based XML, HTTP, SOAP, WSDL 등웹서비스스펙준수 Security WS-Security, WS-Trust 등메시지기반보안제공 HTTPS, 인증기반의 TCP/IP 등트랜스포트수준의보안제공 Transaction 분산트랜잭션지원 TCP 바인딩사용시 OLE Transaction 직접사용 HTTP 바인딩사용시 WS-AT 를통해트랜잭션젂파 Reliability 싞뢰도높은메시징을위해 WS-RM 프로토콜구현 세션기능제공 (ASP.NET 의세션과는다른개념 ) P2P Networking Rich Built-in Bindings BasicHttp, WSHttp, WSDualHttp, NetTcp, NetMsmq, NetNamedPipe 등
PROGRAMMING WCF
WCF Programming Model (1) Basic Concept WCF Endpoint (ABC of WCF Programming) Address 서비스를액세스하기위한주소 Transport 에따라달라짐 http://..., net.tcp://..., net.pipe://..., net.msmq://..., net.p2p://... Binding 서비스호출에사용되는 Transport 프로토콜, 인증, 암호화, 메시지인코딩, 세션여부등 Binding 에의해 Address 형식이결정되곤함 Custom Binding 제공도가능 Contract 서비스에대한인터페이스 서비스의메쏘드 (Operation Contract) 관련데이터타입들 (Data Contract) 하나의 WCF 서비스는다수의 Endpoint 를가질수있음
WCF Programming Model (2) WCF Message EndPoint Address WCF Service #1 Contract Client WCF Message Binding EndPoint Service Implementation Address Contract Client Binding WCF Service #2 WCF Message EndPoint Address Contract Service Implementation Client Binding
WCF Programming Model (3) Service Implementation Transaction Flow Reliable Messaging Message Security Message Encoding Transport Security Transport Service Contract WCF Message Client Transaction Flow Reliable Messaging Message Security Message Encoding Transport Security Transport Server Client
WCF Programming Model (4) Service Implementation Client Enabled Transaction Flow Transaction Flow Enabled N/A Reliable Messaging Reliable Messaging N/A X.509 Token Text Encoding Message Security Message Encoding Service Contract Message Security Message Encoding X.509 Token Text Encoding Use SSL Transport Security Transport Security Use SSL HTTP Transport WCF Message Transport HTTP Server Client
WCF Programming Model (5) Service Implementation Client Disabled Transaction Flow Transaction Flow Disabled Allow Reliable Messaging Reliable Messaging Allow None Binary Encoding None Message Security Message Encoding Transport Security Service Contract Message Security Message Encoding Transport Security None Binary Encoding None TCP Transport WCF Message Transport TCP Server Client
Writing WCF Service (1) 서비스계약정의 WCF 서비스의인터페이스정의 닷넷인터페이스에 ServiceContract 특성명시 인터페이스메쏘드마다 OperationContract 특성명시 데이터계약정의 (optional) Operation 에의해주고받을데이터타입에대한정의 데이터타입에 DataContract, DataMember 특성명시 [ServiceContract] interface [DataContract] IBanking { class TransferInfo { [OperationContract] string from_account_id; void... Deposit(string.. account_id, double amount); } } [OperationContract] [DataMember] void publictransfer(transferinfo string From info); { get { return from_account_id; } set { from_account_id = value; } }......
Writing WCF Service (2) 서비스타입구현 서비스인터페이스에대한구현 서비스인터페이스를구현하는임의의클래스 서비스호스트구현 서비스에대한호스트객체 서비스호출을리스닝하고메시지를서비스에젂달 class BankingImpl : IBanking { string.. address.... = "http://workman/wcf/example/banking.svc"; // 서비스 public 호스트 void객체 Deposit(string 생성 ( 서비스타입 account_id,, 서비스기본 double 주소를amount) 매개변수로전달 ) ServiceHost {... host... = } new ServiceHost(typeof(BankingImpl), new Uri(address)); host.addserviceendpoint( public typeof(ibanking), void Transfer(TransferInfo info) // service contract { new.. BasicHttpBinding(),.... } // binding (http & WS-I profile) ""); // address (use base address)...... } host.open(); // 서비스리스닝시작! ( 비동기적으로작동함 ) // 다른작업을수행하는등의작업수행 host.close();
Writing WCF Client (1) ServiceEndpoint 구성 ` 호출하고자하는 WCF 서비스의 Contract, Binding, Address 를명시 Channel 객체구성 ChannelFactory 객체생성및 Channel 생성 서비스호출! string address = "http://workman/wcf/stepbystep/banking.svc"; ServiceEndpoint ep = new ServiceEndpoint( ContractDescription.GetContract(typeof(IBanking)), // service contract new BasicHttpBinding(), // binding new EndpointAddress(address)); // address ChannelFactory<IBanking> factory = new ChannelFactory<IBanking>(ep); // get channel factory IBanking proxy = factory.createchannel(); // get service interface proxy.deposit("123-45-678-1234", 3000.0); TransferInfo info = new TransferInfo(); info.from = "123-45-678-1234"; info.to = "987-65-432-1234"; info.amount = 2000.0; proxy.transfer(info); factory.close();
Writing WCF Client (2) Proxy 코드자동생성 Using svcutil.exe WCF 클라이언트프록시생성유틸리티 (MSDN 참조 ) Using Visual Studio 2005/2008 Add Service Reference 메뉴사용 반드시 proxy 를 Dispose 해주어야함 (using 사용권장 ) Configuration 에의해서비스종점 (Endpoint) 정보생성 Web Service 프록시와매우유사 Binding 에대한다양한설정포함 Tip 기본적으로 WCF 는 HTTP 에의해 WSDL 을조회를금지하고있음 ( 보안문제 ) 서버에서명시적으로이를해제해야함. 코드혹은 Configuration 이용
Using Service/Client Configuration Using Configuration Service Endpoint 에대한설정을 configuration 으로설정가능 <system.servicemodel> 섹션사용 Service 관련설정및 Client 관련설정 <?xml version="1.0" encoding="utf-8"?> <configuration> <?xml version="1.0" encoding="utf-8"?> <configuration> <system.servicemodel> <system.servicemodel> <services> <bindings> <service name="wcfservicelib.bankingimpl" behaviorconfiguration="servicebehavior"> <wshttpbinding> <endpoint contract="wcfservicelib.ibanking" binding="wshttpbinding" address="" /> </service> <binding name="wshttpbinding_ibanking"...... > </services>...... <behaviors> </binding> <servicebehaviors> </wshttpbinding> </bindings> <behavior name="servicebehavior"> <client> <servicedebug includeexceptiondetailinfaults="true"/> <endpoint<servicemetadata address="http://workman/wcf/example/banking.svc" httpgetenabled="true" /> </behavior> binding="wshttpbinding" bindingconfiguration="wshttpbinding_ibanking" </servicebehaviors> contract="wcfclient.bankingservice.ibanking" name="wshttpbinding_ibanking"> </behaviors> <identity> </system.servicemodel> <userprincipalname value="workman\ksyu33" /> </configuration> </identity> </endpoint> </client> </system.servicemodel> </configuration>
Programming WCF
Conclusion Evolution of Network Communication 새로운요구사항을수용하면서보다편리한개발홖경을제공하는방향으로짂화되어왔음 최근에는 XML 기반의상호운영성이뛰어난통싞방법선호 Windows Communication Foundation XML 웹서비스기반의뛰어난상호운영성 짂보된메시징, 보안, 트랜잭션, 싞뢰성, P2P 등새로운기능 프로토콜에무관한통합된단일프로그래밍모델 기졲 ASMX, WSE,.NET Remoting, COM+ 프로그래밍모델의장점들모두수용 갂결한구현방식 다양하고풍부한프로그래밍홖경 WCF : Microsoft 의차세대커뮤니케이션인프라
Q&A 참고자료 MSDN MSDN Magazine Windows Vista Developer Story 월갂마이크로소프트웨어 2006년 10월호 Inside Developer 칼럼 월갂마이크로소프트웨어 2006년 11월호 Inside Developer 칼럼 월갂마이크로소프트웨어 2006년 12월호 Inside Developer 칼럼 월갂마이크로소프트웨어 2007년 2월호 Inside Developer 칼럼 Windows SDK v6.0 Samples Contact information http://www.simpleisbest.net ksyu33 at theonetech.co.kr ksyu33 at korea.com