Windows Communication Foundation 3.5 was released to general
public in November 2007 which leverages the existing WCF libraries provided as
part of .NET 3.0 and provides further enhancement to the Microsoft’s suite of
distributed application development framework. Windows Communication Foundation
is by far the most comprehensive framework provided for distributed application
development on the .NET platform which can be interoperable, robust, scalable
and easy to develop. The underlying plumbing is mostly handled by the WCF
libraries so the developer’s can focus on creating the business logic instead
of worrying about protocols, sockets and bindings required for communication.
<o:p>In WCF 3.5, the salient enhancements can be listed as
Service Reference Enhancements
Provided Test Client
addition to the Binding Stack.
for REST Style Services
RSS & ATOM Feeds for Services
Support for WCF in a Partial Trust Environment
<st1:city w:st="on"><st1:place w:st="on">AJAX
Support for Consuming WCF Services
Integration and JSON support
Integration between Workflow and WCF<o:p>
The focus of this article is to explore the two utilities
provided by WCF 3.5, WcfSvcHost and WcfTestClient.
For anyone with a understanding of ABC’s of WCF i.e.
Address, Binding and Configuration, it is self evident that a typical WCF
library requires two components for its exposure and consumption i.e. a service
host and a consuming client. A WCF library in itself can be simply defined as
piece of business logic encapsulated with attributes which support nicer things
such as contracts and versioning however; the actual exposure of the service
depends on the hosting application or service.
There are several ways of hosting a WCF service supported in
WCF 3.0 including IIS hosting, Self Hosting, WAS (Windows Activation Service)
and Windows Service hosting. A simple breakdown of hosting options is as
Named pipes, TCP, MSMQ
IIS 5.1 or self-host
Windows <st1:place w:st="on">Vista
HTTP, named pipes, TCP, MSMQ
IIS 7.0/WAS or self-host
Windows Server 2003
Named pipes, TCP, MSMQ Self-host, HTTP
Windows Server 2008
HTTP, named pipes, TCP, MSMQ
IIS 7.0/WAS or self-hos
binding and further details about service end point as well as host are defined
in the config file using the following four elements in the System.ServiceModel
- Services: This element holds
one or more <service> definitions. Each <service> section is
associated with a particular service type and includes any base addresses
and endpoints to be exposed for that type.
- Client: This element holds
one or more <endpoint> definitions for each service endpoint the
client may consume. Each individual <endpoint> includes an address,
binding, and contract matching a service endpoint.
- Bindings: This element holds
one or more binding configuration sections. This makes it possible to
customize a binding instead of using the defaults provided by a standard
binding, such as webHttpBinding.<o:p>
- Behaviors: This element contains <serviceBehaviors> and <clientBehaviors>. At
the host, the <service> configuration section may reference an element
from the <serviceBehaviors> section to apply local behavioral settings to
the service. At the client, endpoints defined in the <client> section may
reference an element from the <clientBehaviors> section to apply local
behavioral settings to the client communication channel.
Therefore, a service can have multiple end points as the
following example shows.
<add baseAddress="http://localhost:8000/WCFInsiders" />
<add baseAddress="net.tcp://localhost:9000/ WCFInsiders" />
<add baseAddress="net.pipe://localhost/ WCFInsiders" />
Using the WcfSvcHost and WcfSvcClient
Now instead of creating a test client and a host with every project, these two new utilities WcfSvcHost and WcfTestClient allow us to seamlessly test a service without having to write extra code or committing to a specific binding. Both of these utilities can be find here.
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\
First you can create a simple WCF Service library project in Visual Studio.NET 2008.
The syntax for WcfSvcHost is as follows.
Usage: WcfSvcHost.exe /service:<PathToServiceDLL> /config:<PathToServiceConfig> [/client:<pathToClientApp>][/clientArgs:<argumentsToBePassedToClientApp>]
As your probably notice that the arguments in the square brackets are optional and therefore, a simple call can be as follows.
WcfSvcHost /Service:MySampleService.dll /config:app.config
And in the example provided with this article, the command line looked like this
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE>WcfSvcHost /service:c:\Development\MySampleService\MySampleService\bin\Debug\MySampleService.dll /config:c:\Development\MySampleService\MySampleService\App.config
Once you’ve started the service host, you have a meta-data end point available which can be used to start the client. In the case of MySampleService, the mex end point is
A typical syntax for WcfTestClient would be
You can specify any metadata address, such as HTTP-GET, or metadata endpoint over HTTP, TCP, or IPC (named pipes). Multiple metadata addresses can also be specified as shown in the statement below
Now the test client can be invoked by using the following command.
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE>WcfTestClient http:
Windows Communication Foundation (WCF) Test Client (WcfTestClient.exe) is a tool which allows testing the service via a generic user interface without writing any custom code. It also displays the response returned from the service.
WCF Service Host can host the following WCF service project types:
• WCF Service Library
• WCF Service
• Sequential Workflow Service Library
• State Machine Workflow Service Library
• WF State Machine Service
• WF Sequential Service
• XAML WF State Machine Service
• XAML WF Sequential Service
• RSS / ATOM Library
• WAP Service
• Web Site Service.
One of the biggest benefits of both of these tools is their stand alone execution capability. These can be used outside visual studio from a command prompt which makes them a highly valuable choice in testing environments where web server is either not available or setting it up requires jumping lots of hoops. Using these utilities makes hosting and testing WCF services much easier. With a lot of practical use in rudimentary testing, I hope developers would find these tools useful in their everyday jobs.
About the Author
Masood works as a Sr. Software Engineer / Technical Lead in a Monrovia
based financial institution where he develops middle tier
architectures, distributed systems and web applications using Microsoft
.NET framework. He holds various professional memberships (ACM, BCS,
and ACS) and several technical certifications including MCSD.NET,
MCAD.NET and SCJP-II. Adnan is attributed and published in print media
and on the web and holds a Masters Degree in Computer Science from Nova
Southeastern University, FL and is currently pursuing his doctoral studies in Machine Learning. Adnan has taught WCF courses at University of California at San Diego and regularly present at local code camps. He is actively involved in the .NET
community as co-founder and president of San Gabriel Valley .NET Developers group.
His blog can be found at www.AdnanMasood.com and he can be reached via
email at adnanmasood at acm.org
HTTP Programming with WCF and the .NET Framework 3.5 - Justin Smith<o:p>
What's New for WCF in Visual Studio 2008 – Juval
Mix 2007 Talk by Don Box and Steve Maine “DEV03 -
Navigating the Programmable Web” http://sessions.visitmix.com/default.asp?event=1011&session=2012&pid=DEV03&disc=&id=1512&year=2007&search=DEV03