Wcf Quickstart


Published on

WCF Quickstart presentation from St Louis Day of .NET 2009

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Wcf Quickstart

  1. 1. WCF Quick Start with Chris Deweese<br />
  2. 2. .NET Architect<br />Specialties: SOA, Xml, Distributed Messaging<br />Primarily work on System Integration & Information Sharing projects<br />2009 Microsoft MVP, Solutions Architect <br />Twitter @cdeweese – use #stldodn for conference<br />http://christopherDeweese.com/<br />Avid Xbox player (when kids are sleeping)<br />About Chris Deweese<br />
  3. 3. Agenda<br />Why & What of WCF<br />Building a service<br />Lessons Learned<br />
  4. 4. Why Services?<br />Encapsulation of business capabilities. <br />“Unit of work exposed to the world” – Juval Lowy<br />Support multiple front-ends with one service<br />Exposes data model using contracts (Schema, WSDL)<br />Improves interoperability and automation<br />
  5. 5. What is WCF?<br />Framework for building service-oriented applications<br />Separates the logic of services from the channels they communicate on<br />Messages based on Simple Object Access Protocol (SOAP) <br />Support for REST & Plain-old Xml (POX) in .NET 3.5<br />
  6. 6. Why WCF?<br />Evolution of service oriented thinking<br />Remoting, Message Queuing, and ASMX were designed on different stacks<br />WCF unifies the programming model for exposing services through different channels (Web, Message Queues, Sockets, In-Process)<br />Service logic and function is not dependent on the channel or transport<br />
  7. 7. Key Concepts<br />Service – Unit of work exposed to the world.<br />Endpoint – the collection of the services address, binding, and contract.<br />Address – The network location of the service(e.g., http://localhost/home/home.svc)<br />Binding – How you interact with the service at the wire level.<br />Channel – The transport mechanism that moves the message between service and client.<br />Dispatcher – Manages execution of service code by routing messages to the appropriate service instance and method.<br />Behavior – How you control the local execution of a service.<br />
  8. 8. WCF Extensibility<br />WCF built for extensibility<br />Base classes & interfaces provided which are the gateway to extending WCF<br />Leverages dependency injection principle and factories to hook your extensions into the framework at runtime<br />Support for building custom channels, bindings, etc<br />Lots of “knobs and switches” to tweak WCF through configuration or code attributes<br />
  9. 9. ABC’s of WCF<br />
  10. 10. Address<br />“Dude where’s my service?”<br />The location of the service on the network where it can be reached.<br />http://localhost/pizza.svc<br />net.msmq://localhost/private/pizzaservice<br />net.tcp://localhost:6000/pizzaservice<br />Set via configuration or through code<br />
  11. 11. Binding<br />“How do I talk to this thing?”<br />The protocol and policies used to connect to the service at it’s address.<br />WCF Provided Bindings<br />Http(BasicHttp, WsHttp, WsDualHttp, WsFederation)<br />NetMsmq<br />MsmqIntegration<br />NetNamedPipe<br />NetTcp<br />NetPeerTcp<br />Set via configuration or through code<br />
  12. 12. Contract<br />“What’s it going to do for me?”<br />Defines the operations, inputs, outputs, and message exchange patterns of the service.<br />Defined using an Interface; wired into WCF by using the ServiceContract attribute. Methods use the OperationContract attribute. Classes use the DataContract attribute and members use the DataMember attribute.<br />WCF Serialization is “Opt-In”<br />
  13. 13. Hosting WCF Services<br />In Process<br />Windows Service<br />Web Service (IIS)<br />Windows Activation Services<br />WAS allows you to host a service on any binding<br />
  14. 14. WCF Architecture<br />
  15. 15.
  16. 16.
  17. 17. Demo Service – Pizzeria Ivan<br />
  18. 18. Pizzeria Ivan <br />Pizzeria Ivan has an existing application they want to service enable.<br />Using WCF, build a service interface around the Pizzeria Ivan application<br />
  19. 19. If you build it…they will come.<br />
  20. 20. Some Opinion, Your Mileage May Vary<br />The default WCF Service project is a good start<br />Placing the contracts and service implementation in the same project creates some amount of coupling<br />Following the Web Service Software Factory guidance a recommended practice is to separate the contracts and implementation<br />Separating the host project leaves you open to target different hosting environments, Web, Windows Service, Windows Activation<br />
  21. 21. Pizzeria Ivan Component Architecture<br />
  22. 22. Lessons Learned<br />Configuration complexity increases when using multiple services and clients in one application<br />.NET 4.0 WCF is touting less configuration.<br />One-way and two-way bindings require different contracts.<br />One-way operations must have a void return (Sub in VB.Net)<br />Very extensible but requires knowledge of WCF stack and careful implementation<br />Example: Message handlers can corrupt messages if used improperly<br />Out of the box you still have to do some work to build a properly scalable and maintainable service – WCF is not “drag & drop”<br />To an architect this is not a bad thing!<br />