使用FastReport.Service.dll创建Web报表服务
主要讲解如何使用FastReport .Net最新版本的WCF服务库——FastReport.Service.dll,创建Web报表服务
操作步骤
- 01
.NET Framework 4.0下打开Visual Studio并创建一个新的ASP.NET Web Application的项目。
- 02
添加引用库FastReport.dll,FastReport.Bars.dll,FastReport.Service.dll。
- 03
在站点根目录上创建一个名为ReportService.svc的文笔文件。
- 04
在文本中增加以下代码: <%@ ServiceHost Service="FastReport.Service.ReportService" %> <%@ Assembly Name="FastReport.Service" %>
- 05
打开web.config,在<configuration>节中增加以下代码: <appSettings> <!-- 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" /> </appSettings> <connectionStrings> <add name="FastReportDemo" connectionString="XsdFile=;XmlFile=C:\Program Files\FastReports\FastReport.Net\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>
- 06
运行站点,来检查Web服务的可用性,出现以下页面便运行成功。