解决Reporting Service 改为Form表单验证之后,Webservice调用失败的问题

在没改Form表单验证情况下Reporting Service Webservice使用的是Windows身份验证,一旦改为Form之后随之带来的麻烦就是WebService的调用失效了,会报错处理。 这个时候就需要重写几个重要的方法:

 /// <summary>
        /// 加载ReportService WebService
        /// </summary>
        private static object Locker = new object();
        public class RenderReport : ReportingService2010
        {
            private string m_authCookieName;
            private Cookie m_authCookie;
            public RenderReport()
            {
                // Set the server URL. You can pull this from a config file or what ever way you want to make it dynamic.

                base.Url = "http://xxx/ReportServer/ReportService2010.asmx"; //在webconfig里面定义一个Reporting service WebServer的地址。 http://xxx/ReportServer/ReportService2005.asmx

                // Calling the LogonUser method defined in the ReportService2005.asmx end point.

                // The LogonUser method authenticates the specified user to the Report Server Web Service when custom authentication has been configured.

                // This is to authenticate against the FBA code and then store the cookie for future reference.

                try
                {
                    base.LogonUser("admin", "123", null);
                }

                catch (Exception)
                {

                }

            }
            /// <summary>
            /// Overriding the method defined in the base class.  重写GetWebRequest方法
            /// </summary>
            /// <param name=”uri”></param>
            /// <returns></returns>
            protected override WebRequest GetWebRequest(Uri uri)
            {

                HttpWebRequest request;

                request = (HttpWebRequest)HttpWebRequest.Create(uri);

                request.Credentials = base.Credentials;

                request.CookieContainer = new CookieContainer();

                if (m_authCookie != null

                )
                {

                    request.CookieContainer.Add(m_authCookie);

                }





                return request;

            }

            /// <summary>

            /// Overriding the method defined in the base class. 重写GetWebResponse

            /// </summary>

            /// <param name=”request”></param>

            /// <returns></returns>
            protected override WebResponse GetWebResponse(WebRequest request)
            {

                WebResponse response = base.GetWebResponse(request);

                string cookieName = response.Headers["RSAuthenticationHeader"];

                if (cookieName != null)
                {

                    m_authCookieName = cookieName;

                    HttpWebResponse webResponse = (HttpWebResponse)response;

                    Cookie authCookie = webResponse.Cookies[cookieName];

                    // save it for future reference and use.

                    m_authCookie = authCookie;

                }

                return response;

            }


            /// <summary>
            /// 先移除拥有此角色的用户对应报表的权限。
            /// </summary>
            /// <param name="context"></param>
            public bool AddUserToReportManage(string UserAccount)
            {

                try
                {
                    lock (this)
                    {
                        //RoleManage_D Role_D = new RoleManage_D();
                        //string RoleInfoId = context.Request["RoleInfoid"];
                        //DataTable elemen = Role_D.GetRoleElemen(RoleInfoId); //获取报表
                        //DataTable user = Role_D.GetRoleUser(RoleInfoId);          //获取用户
                        //if (elemen.Rows.Count <= 0 || user.Rows.Count <= 0)    //判断非空
                        //{
                        //    return;
                        //}
                        bool policys = false;
                        Role rol = new Role();
                        rol.Description = "浏览";
                        rol.Name = "Content Manager";
                        Role[] rols = { rol };
                        Policy pol = new Policy();
                        pol.GroupUserName = UserAccount;
                        pol.Roles = rols;
                        Policy[] UserPolicy = base.GetPolicies("/", out policys);//先获取根路径所有用户和角色 
                        List<Policy> PolicyList = new List<Policy>(UserPolicy);//把获取到的用户添加到泛型集合里面去
                        PolicyList.Add(pol);
                        UserPolicy = PolicyList.ToArray();//重新赋值数组
                        base.SetPolicies("/", UserPolicy);//给报表重新赋予权限
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    return false;
                }

            }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值