WCF Share & Learn

19
 Windows Communication Foundation (WCF)

Transcript of WCF Share & Learn

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 1/19

  Windows CommunicationFoundation (WCF)

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 2/19

Agenda

• Introduction of Remoting and Web services• Introduction of WCF• When you should use it.• What software you need to create a WCF service•  Advantages of WCF•  Architecture of WCF• Programming with WCF

• Services Service !"ecution #oundaries$ WCF % &ocation 'rans(arencies)• Contracts Service$ *ata$ Fault and +essage)•  Addresses 'CP$ ,''P$ IPC$ +S+- and PP)• ,osting IIS$ Self$ WAS$Windows)

• #indings• !nd Points• !"am(le of WCF % Im(lementations

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 3/19

Introduction of WCF

• WCF is a set of .NET technologies (Web services ,.NetRemoting and enterprises services) for building and runningconnected sstems.

• WCF provides secure, reliable, and transacted messaging

along !ith interoperabilit

• WCF applications can be developed in an language !hich cantarget the .NET runtime

• "stem."ervice#odel is the assembl that contains corefunctionalit for WCF.

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 4/19

When you should use it.

• When our business logic has to interact !ith a variet of clientapplications.

• When client apps, !hich are going to use our service, ma be!ritten in $ava or .Net.

•  %ou are targeting a distributed computing architecture.

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 5/19

Softwar s r quir d to cr at WCF

•   /isual studio .0et Framewor1 2.3

• +icrosoft Windows Software *evelo(ment 4it S*4)

• /isual studio e"tensions for WCF .

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 6/19

Advantages of WCF

•  +a1es 5I (rogramming % distributed (rogramming very easy.

• Reduce com(le"ity by allowing us to focus on single (rogrammingmodel rather than learn multi(le (rogramming models.

•   ,el(s us tal1 to various a((lications written in various languages withease which means more (robable revenues as various a((lications canstart using your core services with ease.

•   ,el(s us forget about intero(erability between various underlying webservice technologies in the (ast$ (resent and future.

•   With WCF$ a single service can be defined and e"(osed over multi(leend(oints to su((ort multi(le (rotocols at the same time.

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 7/19

WCF Architecture 6verview

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 8/19

Services in WCF

  'he WCF a((lications e"(ose the functionality through services. A Service

enca(sulate business functionality and e"(oses a set of methods that can beaccessed by remote clients.

• When a((lied to a class$ the class becomes a service ty(e. When a((lied to an

interface$ any class that im(lements the interface becomes a service ty(e.

• In either case$ methods e"(osed by the class or interface must be decoratedwith the 6(erationContractAttribute to be considered (art of theservicecontract. +ethods with this attribute are considered service o(erations.

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 9/19

Addresses

  'he address (rovides two im(ortant elements7 the location of theservice and the trans(ort (rotocol or trans(ort schema used tocommunicate with the service.

a) 'CP Addresses  !". net.tc(788localhost79338+yService.

  b) ,''P Addresses  !". htt(788localhost7933: 

c) IPC Addresses  !". net.(i(e788localhost8+yPi(e

  d) +S+- Addresses!". net.msm;788localhost8+yService

 

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 10/19

Contracts

  Tpes of contracts&

• a) "ervice Contracts

  *escribe which o(erations the client can (erform on the service.

• b) 'ata Contracts

  *efine which data ty(es are (assed to and from the service.

• c) Fault Contracts

  *efine which errors are raised by the service$ and how the service handles and(ro(agates errors to its clients.

• d) #essage Contracts 

 Allow the service to interact directly with messages.

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 11/19

Hosting

  WCF "ervice osting&

•  IIS ,osting

  ,osting in IIS is very similar to hosting a classic AS+< web service. =ou need to

  create a virtual directory under IIS and su((ly a .svc file.

Su((ort only ,''P (rotocol.

•  Self ,osting

Self>hosting is the name for the techni;ue used when the develo(er is res(onsiblefor (roviding and managing the life cycle of the host (rocess

• Windows Activation Service

  Windows Activation service is a system service available with Windows vista andwindows server 339.

  Su((orts ,tt($ 'CP and named (i(es

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 12/19

Bindings

  WCF grou(s together a set of communication as(ects in bindings. A binding is  merely a consistent$ canned set of choices regarding the trans(ort (rotocol$

  message encoding$ communication (attern$ reliability$ security$ transaction

  (ro(agation$ and intero(erability.

WCF defines nine standard bindings&

• asic inding• TC* inding

• *+* inding

• *C inding

• W" inding

• Federated W" inding

• 'uple- W" inding• #"# inding

• #"# ntegration inding

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 13/19

  /ist of bindings &

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 14/19

Endpoints

The endpoint is the fusion of the address, contract, and binding (0C).

• 0ddress &1 'he address is obviously the location of the service

• inding&1 'he binding s(ecifies security o(tions$ encoding o(tions$ andtrans(ort o(tions.

• Contract&1 'he contract is the actual interface that the service im(lements. 

• !very end(oint must have all three elements$ and the host e"(oses the end(oint.&ogically

• !very service must e"(ose at least one business end(oint and each end(oint

has e"actly one contract. All end(oints on a service have uni;ue addresses$ anda single service can e"(ose multi(le end(oints. 'hese end(oints can use thesame or different bindings and can e"(ose the same or different contracts..

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 15/19

Saple WCF

• Class

  (ublic class !m(loyee

  ?

  (ublic int Id ? get@ set@

  (ublic string !mail ?get@set@

  (ublic &istB!m(loyee Det!m(&ist)

  ?

  &istB!m(loyee em(&ist E new &istB!m(loyee)@

  em(&ist.Addnew !m(loyee) ? Id E :$ !mailEArmanGsomemail.com)@

  em(&ist.Addnew !m(loyee) ? Id E :$ !mail E ArnabGsomemail.com )@

 return em(&ist@

 

 

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 16/19

• nterface

  HServiceContract  (ublic interface I!m(loyeeService

  ?  H6(erationContract  &istB!m(loyee Fetch!mail&iststring mail)@ 

• nterface mplementation

(ublic class !m(loyeeService 7 I!m(loyeeService  ?  (ublic &istB!m(loyee Fetch!mail&iststring mail)  ?  var em( E new !m(loyee)@  var fetch!mail E em(.Det!m(&ist)

  .Wherem E m.!mail.'o&ower).StartsWithmail.'o&ower)))@  return fetch!mail.'o&ist)@ 

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 17/19

  Jfunction ) ?  J.tb).autocom(lete?  source7 function re;uest$ res(onse) ?  J.aKa"?  url7 !m(loyee&ist.svc8Fetch!mail&ist$  data7 ? LmailL7 L M re;uest.term M L $  data'y(e7 Kson$  ty(e7 P6S'$  content'y(e7 a((lication8Kson@ charsetEutf>9$  dataFilter7 function data) ? return data@ $

  success7 function data) ?  res(onseJ.ma(data.d$ function item) ?  return ?  value7 item.!mail    ))  $

  error7 function <+&,tt(Re;uest$ te"tStatus$ error'hrown) ?  alertte"tStatus)@    )@  $  min&ength7   )@

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 18/19

Bsystem.service+odel

  Bservices  Bservice nameEService  Bend(oint addressEsoa( contractEIService bindingEbasic,tt(#inding8

  Bend(oint addressErest contractEIService bindingEweb,tt(#indingbehaviorConfigurationErest#ehavior8

  Bend(oint contractEI+etadata!"change bindingEme",tt(#inding addressEme" 8  B8service  B8services  Bbehaviors  Bend(oint#ehaviors  Bbehavior nameErest#ehavior  Bweb,tt( hel(!nabledEtrue8  B8behavior  B8end(oint#ehaviors  Bservice#ehaviors  Bbehavior  Bservice+etadata htt(Det!nabledEtrue8  Bservice*ebug include!"ce(tion*etailInFaultsEtrue 8

  B8behavior  B8service#ehaviors  B8behaviors  Bservice,osting!nvironment multi(leSite#indings!nabledEtrue 8  B8system.service+odel

7/23/2019 WCF Share & Learn

http://slidepdf.com/reader/full/wcf-share-learn 19/19

Thank You