FastReport.Net v2016.6 FastScript安装 安装 VCL mvc FastReport.Net 报表 FastReport.Net v2016.2 TeeChart,图表开发 FastReport FMX 2.3 FastReport.Net v2016.1 FastReport.Net更新 FastCube VCL v2.5 FastReport VCL FastReport Online Designer教程 FastReport Online Designer组件 FastReport在线报表设计器:组件简介 FastReport在线报表设计器:界面结构简介 FastReport在线报表设计器:工作原理 FastReport Online Designer简介 FastReport Online Designer促销 FastReport Online Designer FastReport.Net授权促销 数据库查询构建 使用技巧 fastreport,报表 脚本引擎 FastScript FastScript, 脚本引擎 OLAP控件
作者:mikez 来源:本站原创 浏览:Loading... 日期:2013-08-23
今天我们将创建一个Windows服务,它将作为WCF服务运行。演示实例将建立于library FastReport.Service.dll(WCF Service Library)的基础之上,它将会在package of FastReport .NET中被找到。
打开Visual Studio并创建一个WindowsService项目。
打开designer of service1.cs
自行更换服务名称。
在窗口点击鼠标右键并选择“Add Installer”。
编辑serviceInstaller1组件的属性——设置一个展示名称。
在组件属性中,serviceProcessInstaller1 设置一个LocalSystem服务的账户类型。
在 System.ServiceModel 和 FastReport.Service.dll 添加 references。
创建应用配置文件。
复制如下文本至新的app.config
<?xml version="1.0"?>
<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.web>
<compilation debug="true" />
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</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 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" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/FastReportService/" />
</baseAddresses>
</host>
</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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
到Service1.cs 的编辑器并添加如下一行:
using System.ServiceModel;
然后您需要修改Service Class,由此看着如下图所示。
public partial class ReportService : ServiceBase
{
ServiceHost reportHost;
public ReportService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
if (reportHost != null)
reportHost.Close();
reportHost = new ServiceHost(typeof(FastReport.Service.ReportService));
reportHost.Open();
}
protected override void OnStop()
{
reportHost.Close();
reportHost = null;
}
}
编辑项目并确保没有错误。
您可以用命令行工具InstallUtil.exe来安装服务。
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "C:\MyProjects\WcfService1\WindowsService1\bin\Debug\WindowsService1.exe"
你还可以用指令开启服务:
net start ReportService打开网页浏览器查看http://localhost:8732/FastReportService/,它在baseAddress的应用程序配置中。您可以自行改变文件夹和端口。
停止和卸载服务的指令如下:
net stop ReportService
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /u "C:\MyProjects\WcfService1\WindowsService1\bin\Debug\WindowsService1.exe"
您可以在最新版本的Fastreport .NET的"\Demos\C#\WCFWindowsService"文件夹内看到这个示例。
Tag标签:fastreport
慧都科技旗下网站-FastReport中文网版权所有 Copyright 2012
FastReport,报表控件,FastReport报表,VCL报表,.NET报表,COM/ActiveX报表,OLAP控件,联机分析处理