使用FastReport.Service.dll創建Web服務
有一種簡單的方法可以使用 FastReport.Service.dll(WCF 服務庫)庫來實現 Web 服務,該庫隨 FastReport .Net 一起提供。
我們的示例基于創建一個具有 Web 服務功能的簡單 Web 應用程序,但您可以基于 .NET Framework 4.0 或更高版本修改現有項目。
運行 Visual Studio 并在 .NET Framework 4.0 下創建一個新的 ASP.NET Web 應用程序項目。
添加對庫 FastReport.dll、FastReport.Bars.dll、FastReport.Service.dll 的引用。
在站點根目錄中創建一個名為 ReportService.svc 的新文本文件。
將這些行添加到文件中:
<%@ ServiceHost Service="FastReport.Service.ReportService" %> <%@ Assembly Name="FastReport.Service" %>
點擊復制
<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>
點擊復制
鍵“FastReport.ReportsPath”應包含包含報告的文件夾的路徑。例如,您可以將其設置為演示文件夾“\FastReport.Net\Demos\WCF”。
鍵“FastReport.ConnectionStringName”應包含連接字符串名稱。該行應在部分中注冊。
讓我們運行我們的站點并通過訪問文件 ReportService.svc 來檢查 Web 服務的可用性。
在服務器上部署項目時,請務必檢查文件 FastReport.dll、FastReport.Bars.dll、FastReport.Service.dll 是否位于文件夾 \bin 中。
客戶端程序的示例可以在文件夾 \FastReport.Net\Demos\C#\WCFClient 和 \FastReport.Net\Demos\C#\WCFWebClient 中找到。在 Visual Studio 中打開每個項目,右鍵單擊 ReportService 并在彈出窗口中選擇“配置服務引用”。
在配置窗口中指定現有 Web 服務的地址。