注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

天涯倦客的博客

祝福你朋友永远快乐!

 
 
 

日志

 
 

Reporting Services 4: Web Service  

2012-02-20 18:13:42|  分类: asp.net |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
Reporting Services提供了一个基于Web的报表管理器Report Manager,其主要功能是通过是调用报表服务器提供的Web Service来完成的,可以使用类似于http://(ServerName)/Reports$(InstanceName)的URL来了解报表管理器的全貌。Reporting Services的Web Service是客户端程序和报表服务器之间的通信接口,允许开发者创建任何涵盖整个报表生命周期的相关自定义工具(除了类似于报表管理器的报表管理功能外,还具备生成、发布、打印报表等功能)。


图1 报表管理器Report Manager

在上一篇随笔《Reporting Services 3: 报表模型项目》中提到过“由于这种即席报表是由终端用户设计的,终端用户并不负责完成在应用程序中引用该报表的工作,这项工作应该由应用程序自动来完成,在以后的随笔中将介绍如何实现这项工作。”,这篇随笔就要解决这个问题,当然解决的方法就是通过使用Reporting Services提供的Web Service来完成的。其实,我们要做的工作很简单:创建一个Web应用程序,列举由某个用户创建的所有报表(可能存在多个不同的文件夹中),并可以通过报表的链接使用ReportViewer控件显示不同的报表。

1、在Visual Studio 2005中创建一个ASP .NET网站RSWS。

2、在Default.aspx中添加一个TreeView控件用于以目录的形式列举报表,然后添加一个ReportViewer控件用于显示报表。

3、在“解决方案资源管理器”中,为网站RSWS“添加 Web 引用”,如图2所示,在URL列表框中输入报表服务器提供的Web Service的地址http://(ServerName)/ReportServer$(InstanceName)/ReportService.asmx。


图2 添加Reporting Services的Web Service引用(点击小图看大图)

如上图所示,Reporting Services的Web Service的文档也告诉我们:Reporting Services的Web Service允许我们管理报表服务器及其服务器设置、安全、报表、订阅和数据源等的内容。

4、在Default.aspx.cs中添加如下代码:

Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
1Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using System;
2Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Data;
3Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Configuration;
4Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Collections;
5Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Web;
6Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Web.Security;
7Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Web.UI;
8Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Web.UI.WebControls;
9Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Web.UI.WebControls.WebParts;
10Reporting Services 4: Web Service - 海里的贝壳 - apple的博客using
System.Web.UI.HtmlControls;
11
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
12Reporting Services 4: Web Service - 海里的贝壳 - apple的博客public partial class
_Default : System.Web.UI.Page
13Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
14
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
15
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 ReportingWS.ReportingService rs
= new
ReportingWS.ReportingService();
16
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
17
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
/// <summary>
18Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 /// 为Treeview添加节点
19
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
/// </summary>

20Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 /// <param name="tnc">节点集合</param>
21Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 /// <param name="nodepath">节点对象的路径</param>

22Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 private void AddNodes(TreeNodeCollection tnc, string nodepath)
23
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
24
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
//将节点路径中包含的对象列举出来

25Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 ReportingWS.CatalogItem[] items = rs.ListChildren(nodepath, true);
26
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
27
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
for (int i = 0; i < items.Length; i++
)
28
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
29
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
//限制为用户waxdoll\\administrator创建的对象,其中对象又限制为文件夹和报表

30Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 if (items[i].CreatedBy.ToLower() == "waxdoll\\administrator")
31
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
32
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
if (items[i].Type ==
ReportingWS.ItemTypeEnum.Folder)
33
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 tnc.Add(
new TreeNode(items[i].Name, "folder" + items[i].Path, "folder.gif", "", ""
));
34
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
else if (items[i].Type ==
ReportingWS.ItemTypeEnum.Report)
35
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 tnc.Add(
new TreeNode(items[i].Name, "report" + items[i].Path, "report.gif", "", ""
));
36
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

37Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

38Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
39
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 items
= null
;
40
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

41Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
42
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
protected void Page_Load(object
sender, EventArgs e)
43
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
44
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
//设置Web Services客户端身份验证的安全凭据

45Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
46
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
47
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
if (!this
.IsPostBack)
48
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
this.AddNodes(this.trvReport.Nodes, "/"
);
49
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

50Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
51
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
protected void trvReport_SelectedNodeChanged(object
sender, EventArgs e)
52
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
53
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
if (this.trvReport.SelectedNode != null
)
54
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
55
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
string strType = this.trvReport.SelectedNode.Value.Substring(0, 6
);
56
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
57
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
if (strType == "report"
)
58
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
59
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
//选中的节点为报表,则在ReportViewer控件中显示该报表

60Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 this.rvReport.Visible = true;
61
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
//为ReportViewer显示服务器端报表进行的属性设置

62Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 this.rvReport.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
63
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
this.rvReport.ServerReport.ReportServerUrl = new Uri("http://WAXDOLL/ReportServer$BIServer"
);
64
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
this.rvReport.ServerReport.ReportPath = this.trvReport.SelectedNode.Value.Substring(6
);
65
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

66Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 else if (strType == "folder")
67
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
{
68
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
//选中的节点为一个文件夹,如果该文件夹从未展开过,则为其增加节点

69Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 this.rvReport.Visible = false;
70
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
if (this.trvReport.SelectedNode.ChildNodes.Count == 0
)
71
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
this.AddNodes(this.trvReport.SelectedNode.ChildNodes, this.trvReport.SelectedNode.Value.Substring(6
));
72
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

73Reporting Services 4: Web Service - 海里的贝壳 - apple的博客
74
Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

75Reporting Services 4: Web Service - 海里的贝壳 - apple的博客 }

76Reporting Services 4: Web Service - 海里的贝壳 - apple的博客}

示例的运行结果如图3所示:


图3 示例运行结果

Demo下载

Reporting Services的Web Service提供的功能远远要比这里的示例多得多,需要在以后的学习中继续发掘

转载 :http://www.cnblogs.com/waxdoll/archive/2006/07/30/463114.html

  评论这张
 
阅读(872)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017