Exploring WCF 3.5 Tools - WcfSvcHost and WcfTestClient

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.
In WCF 3.5, the salient enhancements can be listed as follows.
  • 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 AJAX Support for Consuming WCF Services
  • Ajax Integration and JSON support
  • Better Integration between Workflow and WCF
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.
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 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
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.
  • 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>  
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
http://msdn.microsoft.com/msdnmag/issues/08/01/WCFinOrcas/default.aspx
What's New for WCF in Visual Studio 2008Juval 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
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
About the Author
Adnan Masood


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
Occupation: Team Leader
Company: Green Dot Corporation
Location: United States United States
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值