分享

FastReport创建托管在windows服务中的WCF服务

 卡咖啡 2013-09-04
在慧都之前的几篇文章中也提到了,报表开发工具FastReport .NET最新的WCF服务库FastReport.Service.dll非常的强大而且易用,今天我们将介绍基于其创建托管在windows服务中的WCF服务的方法。

1、打开Visual Studio并创建一个项目WindowsService(在在线模板中)。

FastReport创建托管在windows服务中的WCF服务

2、用设计器打开Service1.cs

FastReport创建托管在windows服务中的WCF服务

3、修改服务名称,例子中用的是“ReportService”。

FastReport创建托管在windows服务中的WCF服务

4、右键单击窗口,选择“添加安装程序”。

FastReport创建托管在windows服务中的WCF服务

5、修改serviceInstaller1控件的属性,设置DisplayName。

FastReport创建托管在windows服务中的WCF服务

6、在serviceProcessInstaller1属性中选择账户类型为LocalSystem

FastReport创建托管在windows服务中的WCF服务

7、在项目中添加引用System.ServiceModel和FastReport.Service.dll。

FastReport创建托管在windows服务中的WCF服务

8、创建应用程序配置文件

FastReport创建托管在windows服务中的WCF服务

9、在配置文件中添加以下文本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?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>
 </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>

10、编辑Service1.cs,添加以下行:

1
using System.ServiceModel;

11、修改服务类:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;
 }
 }

12、接下来就可以进行开发编码了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多