Creating the WCF service hosted in windows service

Today we will create a Windows service, which will serve as the WCF service. An example will be based on the use of the library FastReport.Service.dll (WCF Service Library), which can be found in the package of FastReport .NET.

Open Visual Studio and create a project WindowsService.

Create Windows Service

Open the designer of Service1.cs

Service Designer

Change the name of the service on your own.

Rename windows service

Click by right mouse button on window and select “Add Installer”.

Add installer in service

Edit the properties of the component serviceInstaller1 - set up a DisplayName.


In the component properties serviceProcessInstaller1 set up the type of account for the service LocalSystem.


Add references in project on System.ServiceModel and FastReport.Service.dll

Add references

Create application configuration file.

Add app.config

Copy the following text into the new app.config

<?xml version="1.0"?>
 <!-- path to folder with reports -->
 <add key="FastReport.ReportsPath" value="C:\Program files\FastReports\FastReport.Net\Demos\WCF" />
 <!-- name of connection string for reports -->
 <add key="FastReport.ConnectionStringName" value="FastReportDemo" />
 <!-- Comma-separated list of available formats PDF,DOCX,XLSX,PPTX,RTF,ODS,ODT,MHT,CSV,DBF,XML,TXT,FPX. 
 You can delete any or change order in this list. -->
 <add key="FastReport.Gear" value="PDF,DOCX,XLSX,PPTX,RTF,ODS,ODT,MHT,CSV,DBF,XML,TXT,FPX" />
 <add name="FastReportDemo" connectionString="XsdFile=;XmlFile=C:\Program Files\FastReports\FastReport.Net\Demos\Reports\nwind.xml"/>
 <compilation debug="true" />
 <membership defaultProvider="ClientAuthenticationMembershipProvider">
 <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
 <roleManager defaultProvider="ClientRoleProvider" enabled="true">
 <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
 <!-- 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. -->
 <service behaviorConfiguration="FastReportServiceBehavior" name="FastReport.Service.ReportService">
 <endpoint address="" binding="wsHttpBinding" contract="FastReport.Service.IFastReportService">
 <dns value="localhost" />
 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
 <add baseAddress="http://localhost:8732/FastReportService/" />
 <behavior name="FastReportServiceBehavior">
 <serviceMetadata httpGetEnabled="True" />
 <serviceDebug includeExceptionDetailInFaults="True" />
 <binding messageEncoding="Mtom"
 closeTimeout="00:02:00" openTimeout="00:02:00"
 receiveTimeout="00:10:00" sendTimeout="00:02:00"
 maxReceivedMessageSize="67108864" maxBufferSize="65536"
 <security mode="None">
 <transport clientCredentialType="None" />
 <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />

Go to the editor of Service1.cs and add the line:

using System.ServiceModel;

Then you need to modify the class of service, so that it looks like:

public partial class ReportService : ServiceBase
 ServiceHost reportHost;
 public ReportService()
 protected override void OnStart(string[] args)
 if (reportHost != null)
 reportHost = new ServiceHost(typeof(FastReport.Service.ReportService));
 protected override void OnStop()
 reportHost = null;

 Compile the project and make sure that there are no errors.

You can install the service using the command line utility InstallUtil.exe, which comes with .NET Framework, such as:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "C:\MyProjects\WcfService1\WindowsService1\bin\Debug\WindowsService1.exe"

And you can start service by command:

net start ReportService

Open web browser and check an address http://localhost:8732/FastReportService/, which set in app.config in baseAddress. You can change folder and port on your own.

Commands for stop and uninstall of the service:

net stop ReportService
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /u "C:\MyProjects\WcfService1\WindowsService1\bin\Debug\WindowsService1.exe"

 You can see this example in latest builds of FastReport .NET in folder "\Demos\C#\WCFWindowsService".

Thank you for attention!


Fast Reports
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.