• <menu id="w2i4a"></menu>
  • logo 報表生成器FastReport .Net程序員手冊
    文檔首頁>>報表生成器FastReport .Net程序員手冊>>報表生成器FastReport .Net程序員手冊:如何在windows服務中創(chuàng)建WCF服務?

    報表生成器FastReport .Net程序員手冊:如何在windows服務中創(chuàng)建WCF服務?


    FastReport .Net是適用于Windows Forms,ASP.NET,MVC和.NET Core的全功能報表解決方案。它可以在Microsoft Visual Studio 2005-2019中使用。支持.Net Framework 2.0-4.x,.NET Core 3.0及以上版本。

    在FastReport .NET 2021.1的新版本中,我們實現(xiàn)了對.NET 5的支持。添加了新消息-Deutsce Post Leitcode。將RTF轉(zhuǎn)換為報告對象的算法已獲得顯著改進。數(shù)字的新功能。歡迎下載體驗。(單擊下方按鈕下載)

    立即點擊下載FastReport.NET v2021.1最新版

    Fastreport.NET在線購買價優(yōu)惠,專享85折起!趕緊加入購物清單吧!

    :Visual Studio,創(chuàng)建一個項目WindowsService。


    :Service1.cs的設計器

    將服務的名稱改為自己選擇的名稱。

    右擊窗口,在拖動的窗口中選擇“添加安裝程序”。

    編輯組件serviceInstaller1的屬性-設置一個DisplayName。

    在serviceProcessInstaller1的組件屬性中,設置服務的帳戶類型為LocalSystem。

    在項目中添加對System.ServiceModel和FastReport.Service.dll的引用。

    創(chuàng)建一個應用程序配置文件。


    將以下文字復制到新的app.config文件中:

    <?xml version =“ 1.0”?> <配置> <appSettings> <!-包含報告的文件夾的路徑-> <add key =“ FastReport.ReportsPath” value =“ C:\ Program files \ FastReports \ FastReport.Net \ Demos \ WCF“ /> <!-報告的連接字符串名稱-> <add key =“ FastReport.ConnectionStringName” value =“ FastReportDemo” /> <!-可用格式的逗號分隔列表PDF,DOCX,XLSX,PPTX,RTF,ODS,ODT, MHT,CSV,DBF,XML,TXT,F(xiàn)PX。 您可以在此列表中刪除任何訂單或更改訂單。-> <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>
    

    Go to the editor of Service1.cs and add the line:

    using System.ServiceModel;
    Modify the class of service so it looks like:
    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來安裝服務,例如,它是.NET Framework自帶的。

    C:\Windows/Microsoft.NET/Framework/v4.0.30319/InstallUtil.exe "C:\MyProjects/WcfService1/WindowsService1/Debug/WindowsService1.exe"

    你可以用命令啟動服務:

    net start ReportService

    打開網(wǎng)頁瀏覽器,查看app.config中baseAddress中設置的地址http://localhost:8732/FastReportService/。你可以把文件夾和端口改成你自己選擇的。

    停止和卸載服務的命令:

    net stop ReportService

    C:\Windows/Microsoft.NET/Framework/v4.0.30319/InstallUtil.exe /u "C:\MyProjects/WcfService1/WindowsService1/bin/Debug/WindowsService1.exe"

    這個例子位于文件夾“ \ Demos \ C#\ WCFWindowsService”中。


    還想要更多嗎?可以您點擊閱讀【FastReport的報表2020最新資源盤點】,查找需要的教程資源。讓人興奮的是FastReport的.NET報表正在慧都網(wǎng)火熱銷售中!低至3701元型態(tài)起!> >查看價格詳情

    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();