![]() |
Platforms, Frameworks & Libraries »
Windows Communication Foundation »
Utilities
License: The Code Project Open License (CPOL)
Exploring WCF 3.5 Tools - WcfSvcHost and WcfTestClientBy Adnan MasoodDisucssing use of WCFSvcHost and WcfTestClient for Service hosting and testing |
C# (C# 1.0, C# 2.0, C# 3.0)
|
||||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
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.
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 follows.
|
Operating System |
Supported Protocol |
Hosting Options |
|
Windows XP |
HTTP Named pipes, TCP, MSMQ |
IIS 5.1 or self-host Self Host |
|
Windows |
HTTP, named pipes, TCP, MSMQ HTTP |
IIS 7.0/WAS or self-host
|
|
Windows Server 2003 |
HTTP Named pipes, TCP, MSMQ Self-host, HTTP |
IIS 6.0 Self Hosting |
|
Windows Server 2008 |
HTTP, named pipes, TCP, MSMQ |
IIS 7.0/WAS or self-hos |
Therefore, a service can have multiple end points as the following example shows.
<host> <baseAddresses> <add baseAddress="http://localhost:8000/WCFInsiders" /> <add baseAddress="net.tcp://localhost:9000/ WCFInsiders" /> <add baseAddress="net.pipe://localhost/ WCFInsiders" /> </baseAddresses> </host>
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
http://localhost:8731/Design_Time_Addresses/MySampleService/Service1/mex
A typical syntax for WcfTestClient would be
WcfTestClient.exe <ServiceMetaDataURI>
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
WcfTestClient.exe http://localhost:8000/ net.tcp://localhost:9000/MEX
Now the test client can be invoked by using the following command.
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE>WcfTestClient http://localhost:8731/Design_Time_Addresses/MySampleService/Service1/mex
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.
Adnan 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
http://msdn.microsoft.com/msdnmag/issues/08/01/WCFinOrcas/default.aspx
What's New for WCF in Visual Studio 2008 � Juval
Lowy
http://msdn.microsoft.com/msdnmag/issues/08/02/Foundations/default.aspx
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
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 3 Feb 2008 Editor: |
Copyright 2008 by Adnan Masood Everything else Copyright © CodeProject, 1999-2009 Web13 | Advertise on the Code Project |