Creating Web Service using FastReport.Service.dll
There is an easy way to implement a web service using the library FastReport.Service.dll
(WCF Service Library), which is supplied with FastReport.
Our example is based on creating a simple web application with web service functions, but you can modify your existing project based on .NET Framework 4.6.2 or later.
Run Visual Studio and create a new ASP.NET Web Application project under .NET Framework 4.6.2 or higher.
Add references to libraries FastReport.dll
, FastReport.Bars.dll
, FastReport.Service.dll
.
Create a new text file with name ReportService.svc in the site root.
Add these lines to the file:
<%@ ServiceHost Service="FastReport.Service.ReportService" %>
<%@ Assembly Name="FastReport.Service" %>
Open web.config
and add this code in <configuration>
section:
<appSettings>
<!-- path to folder with reports -->
<add key="FastReport.ReportsPath" value="C:\Program files\FastReports\FastReport .NET Professional\Demos\Reports" />
<!-- 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" />
</appSettings>
<connectionStrings>
<add name="FastReportDemo" connectionString="XsdFile=;XmlFile=C:\Program Files\FastReports\FastReport .NET Professional\Demos\Reports\nwind.xml"/>
</connectionStrings>
<system.serviceModel>
<services>
<service behaviorConfiguration="FastReportServiceBehavior" name="FastReport.Service.ReportService">
<endpoint address="" binding="wsHttpBinding" contract="FastReport.Service.IFastReportService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="FastReportServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding messageEncoding="Mtom"
closeTimeout="00:02:00" openTimeout="00:02:00"
receiveTimeout="00:10:00" sendTimeout="00:02:00"
maxReceivedMessageSize="67108864" maxBufferSize="65536"
transferMode="Streamed">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
The key FastReport.ReportsPath
should contain a path to the folder with the reports. You can set it to the demo folder \Demos\Reports, for example.
The key FastReport.ConnectionStringName
should contain the connection string name. This line should be registered in section <connectionStrings>
.
Let's run our site and check the availability of a Web service by accessing the file ReportService.svc.
When you deploy the project on the server, be sure to check that files FastReport.dll
, FastReport.Bars.dll
, FastReport.Service.dll
are in the folder \bin.
Examples of client programs can be found in the folders \Demos\C#\Web\WCFWebClient. Open each project in Visual Studio, right-click on ReportService and select Configure Service Reference in the popup.
Specify the address of an existing web service in the configuration window.