C C T B H P N

Lecture #11 - Windows Communication Foundation

WCF Concepts and Examples

Web Resourses:

Content:

This lecture is an introduction to Windows Communication Foundation (WCF). We discuss WCF concepts and present a few examples.
  1. The Syllabus describes topics to be covered, reading material for you to digest before coming to class, and due dates for the assigned projects.
  2. Projects:

    Project #2, Project #3, Project #4, Project2HelpF2018
  3. System Structure

  4. Windows Communication Foundation Presentation:

  5. Tutuorials and Background:

  6. Microsoft Examples with some small edits:

    Note: All but the first of these examples won't run until you have completed the setup described below. That's because most of them host in Internet Information Server (IIS). Microsoft is using only one web application to run any of them and the setup is required for that application switching to work work in IIS. The same is true for all the Microsoft samples (see below).
    WCF Self Host Service
    Microsoft's calculator service, used in many of the MS WCF Samples
    WCF Instances
    Show how to use each of the three server activation models using Microsoft Calculator service.
    WCF Message Concurrency
    Explore effects of message concurrency using Microsoft Calculator service.
    WCF Message Passing
    Illustrate use of message contract with Microsoft Calculator service.
  7. Fawcett examples:

    Note: These examples do not need the setup described in the last lecture. Most of them self-host in windows applications. The few that do use IIS each supply their own web application.
    Most of the examples here are simple demos and have very little error handling. To show you how to add error handling I've taken one of the examples, BasicService - Programmatic, with no error handling, and added that in BasicService - Programmatic Version 2, with exception handling for each of the service methods. See comments in the handout. You will find that enhanced demo in the folder here. The following two demonstrations provide you with most of the technical details you will need to successfully use WCF.
    Hand Crafted WCF Services - BasicHttp, class diagrams, vsdx
    Builds services without using the WCF wizard.
    Both declarative and programmatic construction of channels are illustrated.

    Hand Crafted WCF Services - WSHttp
    Same as BasicHttp except protocol uses Secure Sockets Layer.
    The following diagram and demo focus on how WCF works.
    Service Object Lifetimes - Instancing
    Diagram illustrates management of remote object lifetimes on Server.
    Self-Hosted Strings Service
    Demonstrate service sending strings by value, reference, and receiving out string.
    WCF Wizard-based Service
    This project shows you what the C# WCF wizard generates. It's significantly easier to start from one of my projects.
    The next four demonstrations will provide significant help for Project #4.
    Self Hosted File Service
    Illustrates how to send files in chunks using a WCF service. Timed File Streaming Service
    Illustrates how to use streaming (inherently chunks) of binary files. WCF Message Passing Communication, class diagram, vsd
    Show how to build a simple, effective message-passing system using WCF data contract. WCF Peer-To-Peer Communication, class diagram, vsd
    This example uses both WCF and WPF to build a chat like facility.
  8. Setup Microsoft Examples:

    • Download Microsoft WCF Samples
      This download will result in a directory WF_WCF_Samples in C: by default. There are scores of demo projects here.
    • WCF Samples Documentation
    • One-Time Setup
    • Getting the One-Time Setup to work:
      In order to run these examples you must do the setup described in the last link. However, that will probably fail unless you add some features to Windows.

      The setup uses two batch files: setupvroot.bat and setupCertTool.bat. The first batch file creates an IIS application directory in inetput\wwwroot. Many of the examples are hosted in IIS and all of them use this one application with a little switcheroo magic.

      To do this the batch file needs to run a script that was provided by IIS6, but is not supplied with IIS7 (part of Win8) so you will need to select IIS6 compatability as shown.

      Note:
      In order to run any WCF code in visual Studio you will have to run the IDE as Administrator. Otherwise they will abort due to an authorization failure (with an ugly unhandled exception). Microsoft assumes that no one but an Administrator should be running services.

      I've found that virtually all of the security related demos fail. I haven't had the time to figure out why, but expect that is a consequence of changes in .Net security policies since the examples where created (in 2010).

      There are lots of WCF features that are clearly illustrated by the Microsoft Examples. Most use the same simple calculator example, so once you understand how that works you can focus on the WCF features being demonstrated. I've taken the ones I found most useful and edited their code, mostly adding comments, and put the edited examples here.