原創(chuàng)|使用教程|編輯:郝浩|2013-09-03 15:05:05.000|閱讀 375 次
概述:在慧都之前的幾篇文章中也提到了,報(bào)表開(kāi)發(fā)工具FastReport .NET最新的WCF服務(wù)庫(kù)FastReport.Service.dll非常的強(qiáng)大而且易用,今天我們將介紹基于其創(chuàng)建托管在windows服務(wù)中的WCF服務(wù)的方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在慧都之前的幾篇文章中也提到了,報(bào)表開(kāi)發(fā)工具FastReport .NET最新的WCF服務(wù)庫(kù)FastReport.Service.dll非常的強(qiáng)大而且易用,今天我們將介紹基于其創(chuàng)建托管在windows服務(wù)中的WCF服務(wù)的方法。
1、打開(kāi)Visual Studio并創(chuàng)建一個(gè)項(xiàng)目WindowsService(在在線模板中)。
2、用設(shè)計(jì)器打開(kāi)Service1.cs
3、修改服務(wù)名稱,例子中用的是“ReportService”。
4、右鍵單擊窗口,選擇“添加安裝程序”。
5、修改serviceInstaller1控件的屬性,設(shè)置DisplayName。
6、在serviceProcessInstaller1屬性中選擇賬戶類型為L(zhǎng)ocalSystem
7、在項(xiàng)目中添加引用System.ServiceModel和FastReport.Service.dll。
8、創(chuàng)建應(yīng)用程序配置文件
9、在配置文件中添加以下文本:
<?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="//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>
10、編輯Service1.cs,添加以下行:
using System.ServiceModel;
11、修改服務(wù)類:
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、接下來(lái)就可以進(jìn)行開(kāi)發(fā)編碼了。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)