.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 />
Agenda<br />Why & What of WCF<br />Building a service<br />Lessons Learned<br />
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 />
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 />
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 />
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 />
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 />
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 />
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 />
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 />
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 />
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 />
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 />
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.