Useful WCF Tools
When we work with WCF, we mostly concentrate on the development aspect which involves create, deploy, and manage WCF applications. As a developer, I can suggest that If we utilize various tools available in WCF for debugging, tracing and testing purpose then we can have a smooth development ride with minimum glitches.
WCF Test Client or WcfTestClient.exe
As the name implies, it is a tool which behaves as test client to consume the WCF service. In detail, when we create a service, we can test it
- Either by creating a client application which can call the service, pass some test parameters and sends that input to the service. In reply service sends back the response and we can view the response.
- Or, we can save our effort by using ready to use, WCF Test Client.
How to use it?
To use it, create a new WCF service project and press F5, the WCF Service Host begins to host the service in the project.
Now, WCF Test Client opens and displays a list of service endpoints available. If required, we can pass the parameters and invoke the service. The behavior of Test client will be same as any other real-time client.
Features supported by WCF Test Client
The following is a list of features supported by WCF Test Client:
- Service Invocation: Request/Response and One-way message.
- Bindings: all bindings supported by Svcutil.exe.
- Controlling Session.
- Message Contract.
- XML serialization.
Configuration Editor Tool (SvcConfigEditor.exe)
Once we have created our service then we would require configuration changes to put our service for client use. This includes tasks like exposing an endpoint, contracts etc. For example:
<xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <compilation debug="true" /> </system.web> <!-- When deploying the service library project, the content of the config file must be added to the host's --> app.config file. System.Configuration does not support config files for libraries. --> <system.serviceModel> <services> <service name="CalculatorService.Service1" behaviorConfiguration="CalculatorService.Service1Behavior"> <host> <baseAddresses> baseAddress = "http://localhost:8731/Design_Time_Addresses/CalculatorService/Service1/" /> </baseAddresses> </host> <!-- Service Endpoints --> <!-- Unless fully qualified, address is relative to base address supplied above --> <endpoint address ="" binding="wsHttpBinding" contract="CalculatorService.IService1"> <!-- Upon deployment, the following identity element should be removed or replaced to reflect the identity under which the deployed service runs. If removed, WCF will infer an appropriate identity automatically. --> <identity> <dns value="localhost"/> </identity> </endpoint> <!-- Metadata Endpoints --> <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> <!-- This endpoint does not use a secure binding and should be secured or removed before deployment --> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="CalculatorService.Service1Behavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="True"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="False" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
Phew! Quite a heavy task, if we do it manually. But we can avail the benefits of the Service Configuration Editor (SvcConfigEditor.exe).It allows developers to modify configuration settings for WCF services using a graphical user interface. It can be found under Program File-> Microsoft Visual Studio Tools.
Same config file shown above can easily be generated by following the ‘New Config’ Wizard and providing the values.
Service Trace Viewer Tool (SvcTraceViewer.exe)
First of all, we should know a little bit about Tracing. Tracing involves diagnostic information and tracing messages which shows what is happening throughout our application’s operation.
It can be enabled by configuring tracing in the application’s configuration file.
<system.diagnostics> <trace autoflush="true" /> <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> <listeners> <add name="test" type="System.Diagnostics.XmlWriterTraceListener”/> </listeners> </source> </sources> </system.diagnostics>
The Service Trace Viewer supports three file types:
- WCF Tracing File (.svcLog)
- Event Tracing File (.etl)
- Crimson Tracing File
Have a look at it, Go to File->Open and you can open any supported file listed above.
ServiceModel Metadata Utility Tool (Svcutil.exe)
This tool allows users to create service model code from metadata documents. Users can also create metadata documents from service model code. We can see few commands here.
|svcutil http://service/metadataEndpoint||Generates client code from a running service or online metadata documents.|
|svcutil *.wsdl *.xsd /language:c#||Generates client code from local metadata documents.|
|svcutil /t:metadata http://service/metadataEndpoint||Downloads metadata documents from running services.|
|svcutil myAssembly.dll||Generates metadata documents for service contracts and associated types in an assembly.|
There are few more WCF tools which are not used frequently.
- Find Private Key Tool (FindPrivateKey.exe)
- ServiceModel Registration Tool (ServiceModelReg.exe)
- COM+ Service Model Configuration Tool (ComSvcConfig.exe)
- WS-AtomicTransaction Configuration Utility (wsatConfig.exe)
- WS-AtomicTransaction Configuration MMC Snap-in
- WorkFlow Service Registration Tool (WFServicesReg.exe)
- Contract-First Tool
Please refer http://msdn.microsoft.com/en-us/library/ms732015.aspx for more info on these tools