Monday, June 7, 2010

I have been doing a lot of talking about WCF lately, and thought it would be useful to have a good working example to show anyone interested.

This example makes use of NamedPipeBinding, of course this can easily be changed to any other kind of binding. The exposed services use both request/response and subscribe/publish using callbacks.  The request/response service uses asynchronous calls.  Unfortunately the NamedPipeBinding does not allow use of the Metadata-Exchange (mexHttpBinding) end-point to allow easy client-side discovery and client proxy code generation. In my example netNamedPipeBinding is the best to use seeing as the service is on the same machine.

For more information around choosing a binding see this great blog post  Here is a chart outlining selection of a binding from Soledad Pano's blog. And here's a handy reference to all different bindings and their matching config element (I always get the casing wrong first time)

Most developers I know respond best to a good extensive code example better than long drawn out talks with plenty of acronyms thrown in.  This example is a basic to intermediate use of WCF.

Use Instructions:
  1. If you're using Windows 7 be sure to Unblock the zip before extracting the files (yes you can trust me unless... you're on my black list LOL)
  2. Build the code. Then run the ServiceHostConsole project. This will host the services inside a Console application, then we can run the client application. The client application won't run if the services are not hosted and running somewhere.

  3. Once the console window appears and confirms all the end-points are up, you can detach the Visual Studio debugger.
  4. Now we can run the client application - press F5.

    The first panel "Dashboard" retrieves its data from net-pipe://myservice/status using the IStatusService interface.

    The second panel "Form" retrieves its data from net-pipe://myservice/contact using the IContactDataService interface.

    Here's an overall application schematic:

    Follow the code through, I hope you find it informative.

No comments:

Post a Comment