若要创建处理非安全目录的项目,必须为特定版本的 Visual Studio 配置服务器文件。
按照下列相关章节的说明操作,并记下报表目录的目录文件路径(在之后的过程中会用到):
- “在 Visual Studio .NET 2003 以及 Crystal Report 9 和更高版本中配置服务器文件”
- “在 Visual Studio 2005 或 2008 中配置服务器文件”
转到项目的报表目录,找到要通过服务器文件查看的报表的名称。
在以下步骤中,使用的报表是名为“Hierarchical Grouping.rpt”的示例报表。关于示例报表的信息,请参见“示例报表目录”。
注意 |
|---|
在本节中,您将学习如何设置必要的网络凭据。
首先,将生成一个客户端应用程序来访问存储在服务器文件中的报表,该程序允许对 Web 服务目录进行非安全访问。确定客户端应用程序能正常工作后,接下来将向虚拟目录添加安全访问,然后在客户端应用程序中添加代码来提供 NT 身份验证所需的凭据。
生成用来访问服务器文件报表的客户端应用程序:
打开 Web 或 Windows 窗体。
从“视图”菜单中,单击“代码”。
找到在“项目设置”中创建的 ConfigureCrystalReports() 方法。
在此方法内,声明并实例化 ServerFileReport 类。
Dim myServerFileReport As ServerFileReport = New ServerFileReport()ServerFileReport serverFileReport = new ServerFileReport();将报表目录中要显示的报表的名称赋给 ServerFileReport 实例的 ReportPath 属性。
<table>
<colgroup>
<col style="width: 100%" />
</colgroup>
<thead>
<tr class="header">
<th><img src="images/8yfdxzdx.alert_note(zh-cn,VS.90).gif" alt="Note" class="note" />注意</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><p>该目录就是在 Web.config 文件中为服务器文件报表配置的目录。</p></td>
</tr>
</tbody>
</table>
之前,在配置查看器的虚拟目录时,您已经通过在查看器的虚拟目录中输入 Web 服务 ServerFileReportServer.asmx 的 URL 对 wsdl 进行了测试。在下一步中,将把该 URL 作为值输入到代码中。
下面的代码示例使用 Hierarchical Grouping 报表,该报表包含在 Sample Reports 文件夹的 Feature Examples 子目录内。确保包括后跟反斜杠的子目录名。
``` vb
myServerFileReport.ReportPath = "Feature Examples\Hierarchical
Grouping.rpt"
```
``` csharp
serverFileReport.ReportPath = "Feature Examples\\Hierarchical
Grouping.rpt";
```
- 找到您的 Crystal Reports 版本的 Web 服务 ServerFileReportService.asmx 的 URL 正确版本。
如果安装了 Crystal Reports 开发人员版,则它为已安装的 Crystal Reports 版本的查看器虚拟目录(请参见[“查看器虚拟目录”](ms225591\(v=vs.90\).md))。
如果安装了 Crystal Reports for Visual Studio,并且尚未安装 Crystal Reports 开发人员版,则它是[“在 Visual Studio 2005 或 2008 中配置服务器文件”](ms225505\(v=vs.90\).md)时创建的报表 Web 服务的 URL。
- 将此 Web 服务 URL 赋给 ServerFileReport 实例的 WebService 属性。
``` vb
myServerFileReport.WebServiceUrl =
"https://localhost/CrystalReportsWebServices/ServerFileReportService.asmx"
```
``` csharp
serverFileReport.WebServiceUrl =
"https://localhost/CrystalReportsWebServices/ServerFileReport.asmx";
```
这样就完成了对 ServerFileReport 实例的配置,可以将其传递给 CrystalReportViewer 控件了。
将 ServerFileReport 实例赋给 ReportSource 控件的 CrystalReportViewer 属性。
myCrystalReportViewer.ReportSource = myServerFileReportcrystalReportViewer.ReportSource = serverFileReport;
注意