Using WCF Service Host (wcfSvcHost.exe)

Windows Communication Foundation (WCF) Service Host (wcfSvcHost.exe) allows you to launch the Visual Studio debugger (F5) to automatically host and test a service you have implemented. You can then test the service using WCF Test Client (wcfTestClient.exe), or your own client, to find and fix any potential errors.

Auto Hosting

WCF Service Host enumerates the services in a WCF service project, loads the project’s configuration, and instantiates a host for each service that it finds. The tool is integrated into Visual Studio through the WCF Service template and is invoked when you start to debug your project.

By using WCF Service Host, you can host a WCF service (in a WCF service project) without writing extra code or committing to a specific host during development.

WCF Service Host can host the following WCF service project types: WCF 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 Library, WAP Service, and Web Site Service.

Since WCF Service Host is built as a stand-alone executable, you can also use it outside Visual Studio through the Command Prompt window.

You should note, however, that the tool will not help you to configure a host. For this task, you must manually edit the App.config file. The tool also does not validate user-defined configuration files.

WCF Service Host Command Syntax

You can use WCF Service Host from the Command Prompt window using the following syntax.

WcfSvcHost.exe /client:"MyClient.exe" /clientArg:"string of arguments"

where:

Parameter | Meaning
/client | An optional parameter that specifies the path to an executable to run after the services are hosted. This launches WCF Test Client following hosting.
/clientArg | Specify a string as an argument that is passed to the custom client application.
/? | Displays the help text.

Scenarios for Using WCF Service Host

Inside Visual Studio

Using WCF Test Client

After you create a new WCF service project and press F5 to start the debugger, WCF Service Host starts hosting all the services it finds in your project. WCF Test Client automatically opens and displays a list of service endpoints defined in the configuration file. From the main window, you can test the parameters and invoke your service. You can also quickly shut down WCF Service Host by right-clicking its icon in the notification area.

To make sure that WCF Test Client is used, right-click on your project in Solutions Explorer in Visual Studio, select Properties, then select the Debug tab. Click Start Project and ensure that the following appears in the Command line arguments dialog box.

/service:WcfServiceLibrary1.dll /config:WcfServiceLibrary1.dll.config /client:wcfClient.exe

Using a Custom Client

To use a custom client, right-click on your project in Solutions Explorer in Visual Studio, select Properties, then select the Debug tab. Click Start Project and edit the /client parameter in the Command line arguments dialog box to point to your custom client, as indicated in the following example.

WcfSvcHost.exe /service:WcfServiceLibrary1.dll /config:WcfServiceLibrary1.dll.config /client:"path/CustomClient.exe"

When you press F5 to start the service again, WCF Service Host automatically starts your custom client when you launch the debugger.

You can also use the /clientArg: parameter to specify a string as an argument that is passed to the custom client application, as indicated in the following example.

WcfSvcHost.exe /service:WcfServiceLibrary1.dll /config:WcfServiceLibrary1.dll.config /client:"path/CustomClient.exe" /clientArg:"arguments that are passed to Client"

Specifiying No Client

To specify that no client will be used, right-click on your project in Solutions Explorer in Visual Studio, select Properties, then select the Debug tab. Click Start Project and leave the Command line arguments dialog box blank.

Using a Custom Host

To use a custom host, right-click on your project in Solutions Explorer in Visual Studio, select Properties, then select the Debug tab. Click Start External Program and enter the full path to the custom host. You can also use the Command line arguments dialog box to specify arguments to be passed to the host.

WCF Service Host User Interface

When you initially invoke WCF Service Host (either by pressing F5 inside Visual Studio or by launching WCF Service Host from the Command Prompt window), the WCF Service Host window automatically opens. When WCF Service Host is running, the program's icon appears in the notification area. Double-click on the icon to open the WCF Service Host window Right-click the icon and click Exit to shut down WCF Service Host; this also stops all hosted services.

WCF Service Host showing the icon in the notification area.

The WCF Service Host main window contains two menus:

  • File: Contains the Close command. When you click Close, the WCF Service Host dialog box closes, but the services continue to be hosted.

  • Help: Contains the About command that contains version information.

The main WCF Service Host window contains four columns:

  • Service: Lists all the services.

  • Status: Lists the status of the service. Valid values are "Started”, “Stopped,” and “Aborted”.

  • Metadata Address: Displays the metadata address of the services.

  • Message: Displays a detailed explanation of the service status. If the status is aborted, you can view the full error message on the screen.

Stopping WCF Service Host

You can shut down WCF Service Host in the following three ways:

  • Stop the debugging session in Visual Studio.

  • Select Exit from the File menu in the WCF Service Host window.

  • Exit WCF Test Client if it's being used.

Send comments about this topic to Microsoft.