Click here to Skip to main content
15,879,239 members
Articles / Artificial Intelligence / Machine Learning
Article

Exploring WCF 3.5 Tools - WcfSvcHost and WcfTestClient

Rate me:
Please Sign up or sign in to vote.
3.73/5 (8 votes)
3 Feb 2008CPOL6 min read 110.4K   1.5K   35   11
Disucssing use of WCFSvcHost and WcfTestClient for Service hosting and testing

Introduction

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 follows.
<o:p>

  • Add Service Reference Enhancements
  • Various New Tools
    • WCF Provided Test Client
    • WCF Provided Host
  • UriTemplates Support
  • webHttpBinding addition to the Binding Stack.
  • Support for REST Style Services
  • Create RSS & ATOM Feeds for Services
  • More WS-* Protocols
  • Better Support for WCF in a Partial Trust Environment
  • ASP.NET <st1:city w:st="on"><st1:place w:st="on">AJAX Support for Consuming WCF Services
  • Ajax Integration and JSON support
  • Better 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.

Background

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.
<o:p>

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 <st1:place w:st="on">Vista

HTTP, named pipes, TCP, MSMQ

HTTP

IIS 7.0/WAS or self-host


IIS 6.0

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

<o:p>The 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 class.

  • 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.

<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/WCFInsiders" />
<add baseAddress="net.tcp://localhost:9000/ WCFInsiders" />
<add baseAddress="net.pipe://localhost/ WCFInsiders" />  
</baseAddresses>   
</host>  

<o:p>

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.

WCFLibrary_dialog.JPG


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

WCFService_Host.JPG


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

WCF_Test_Client.JPG


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.

Conclusion.

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

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

References

HTTP Programming with WCF and the .NET Framework 3.5 - Justin Smith<o:p>
http://msdn.microsoft.com/msdnmag/issues/08/01/WCFinOrcas/default.aspx<o:p>

What's New for WCF in Visual Studio 2008Juval Lowy <o:p>
http://msdn.microsoft.com/msdnmag/issues/08/02/Foundations/default.aspx<o:p>

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Green Dot Corporation
United States United States
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

Comments and Discussions

 
QuestionDoes the WcfSvcHost command work in later versions of VS? Pin
Mohammad Abu-Ali3-May-17 3:16
Mohammad Abu-Ali3-May-17 3:16 
QuestionMultipe WCF Web Services(.NET Frame Work 3.5) with WCFSVCHost in IIS 7.5 Pin
MrKyaw9-Jan-13 16:04
MrKyaw9-Jan-13 16:04 
QuestionLove Your Article But... Pin
SimbarasheM15-Aug-11 8:03
SimbarasheM15-Aug-11 8:03 
GeneralNice Article Pin
Sathishkumar_P8-Nov-10 3:45
Sathishkumar_P8-Nov-10 3:45 
Generalanother good tool for testing wcf is soa cleaner Pin
amosygal18-Nov-09 21:04
amosygal18-Nov-09 21:04 
GeneralWCF Load testing + functional testing Tool Pin
Erik Araojo (Avalonia/gRPC)19-Apr-09 17:49
Erik Araojo (Avalonia/gRPC)19-Apr-09 17:49 
QuestionWcfSvcHost on build server Pin
scott4dev16-Jan-09 4:17
scott4dev16-Jan-09 4:17 
GeneralWcfSvcHost on build server Pin
scott4dev16-Jan-09 4:16
scott4dev16-Jan-09 4:16 
Generalnice Pin
meetsenthilbtech6-May-08 0:57
meetsenthilbtech6-May-08 0:57 
GeneralNice. This is real useful Pin
Sacha Barber4-Feb-08 0:18
Sacha Barber4-Feb-08 0:18 
GeneralRe: Nice. This is real useful Pin
Member 133990319-Mar-08 13:14
Member 133990319-Mar-08 13:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.