调试从Java应用程序调用的SSRS C#DLL

调试从Java应用程序调用的SSRS C#DLL,c#,debugging,dll,C#,Debugging,Dll,我正在为我的公司实施Microsoft SQL Service Reporting Services。SSR将从我们公司的Java web应用程序调用。我们决定在从JavaWeb应用程序请求SSRS报告时使用单点登录方法。在这种情况下,我们通过自定义安全扩展使用表单身份验证来实现单点登录。您可能已经知道,在用户提交UILogon.aspx页面后,将创建一个票证并将其放入名为sqlAuthCookie的cookie中。当用户向SSR发出任何后续请求时,此cookie(票据)将用于授权 我遇到的问题

我正在为我的公司实施Microsoft SQL Service Reporting Services。SSR将从我们公司的Java web应用程序调用。我们决定在从JavaWeb应用程序请求SSRS报告时使用单点登录方法。在这种情况下,我们通过自定义安全扩展使用表单身份验证来实现单点登录。您可能已经知道,在用户提交UILogon.aspx页面后,将创建一个票证并将其放入名为sqlAuthCookie的cookie中。当用户向SSR发出任何后续请求时,此cookie(票据)将用于授权

我遇到的问题是,用C#编写并作为.dll驻留在SSRS服务器上的表单身份验证代码似乎没有创建票据并将其放入sqlAuthCookie cookie中。我已经检查了Java web应用程序中的sqlAuthCookie cookie。通过访问响应标头中的RSAuthenticationHeader,sqlAuthCookie cookie不包含值

因此,我想知道的是,是否有一种方法可以将表单身份验证代码(即.dll)放入Visual Studio内的调试中,这样,当我从Java web应用程序登录到SSRS时,我可以单步执行此代码,以验证它是否正在为cookie创建票证

如果您需要代码片段,请告诉我

代码

private void BtnLogon_Click(object sender, System.EventArgs e)
      {
         bool passwordVerified = false;
         try
         {
            ReportServerProxy server = new ReportServerProxy();

            string reportServer = ConfigurationManager.AppSettings["ReportServer"];
            string instanceName = ConfigurationManager.AppSettings["ReportServerInstance"];

            // Get the server URL from the report server using WMI
            server.Url = AuthenticationUtilities.GetReportServerUrl(reportServer, instanceName);

            server.LogonUser(TxtUser.Text, TxtPwd.Text, null);

            passwordVerified = true;

         }
         catch (Exception ex)
         {
            lblMessage.Text = string.Format(CultureInfo.InvariantCulture, ex.Message); ;
            return;
         }
         if (passwordVerified == true)
         {
            lblMessage.Text = string.Format(CultureInfo.InvariantCulture,
              UILogon_aspx.LoginSuccess);
            string redirectUrl =
               Request.QueryString["ReturnUrl"];
            if (redirectUrl != null)
               HttpContext.Current.Response.Redirect(redirectUrl, false);
            else
               HttpContext.Current.Response.Redirect(
                  "./Folder.aspx", false);
         }
         else
         {
            lblMessage.Text = string.Format(CultureInfo.InvariantCulture,
             UILogon_aspx.InvalidUsernamePassword);
         }
      }
   }

   // Because the UILogon uses the Web service to connect to the report server
   // you need to extend the server proxy to support authentication ticket
   // (cookie) management
   public class ReportServerProxy : ReportingService2005
   {
      protected override WebRequest GetWebRequest(Uri uri)
      {
         HttpWebRequest request;
         request = (HttpWebRequest)HttpWebRequest.Create(uri);
         // Create a cookie jar to hold the request cookie
         CookieContainer cookieJar = new CookieContainer();
         request.CookieContainer = cookieJar;
         Cookie authCookie = AuthCookie;
         // if the client already has an auth cookie
         // place it in the request's cookie container
         if (authCookie != null)
            request.CookieContainer.Add(authCookie);
         request.Timeout = -1;
         request.Headers.Add("Accept-Language",
            HttpContext.Current.Request.Headers["Accept-Language"]);
         return request;
      }

      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes")]
      protected override WebResponse GetWebResponse(WebRequest request)
      {
         WebResponse response = base.GetWebResponse(request);
         string cookieName = response.Headers["RSAuthenticationHeader"];
         // If the response contains an auth header, store the cookie
         if (cookieName != null)
         {
            Utilities.CustomAuthCookieName = cookieName;
            HttpWebResponse webResponse = (HttpWebResponse)response;
            Cookie authCookie = webResponse.Cookies[cookieName];
            // If the auth cookie is null, throw an exception
            if (authCookie == null)
            {
               throw new Exception(
                  "Authorization ticket not received by LogonUser");
            }
            // otherwise save it for this request
            AuthCookie = authCookie;
            // and send it to the client
            Utilities.RelayCookieToClient(authCookie);
         }
         return response;
      }

      private Cookie AuthCookie
      {
         get
         {
            if (m_Authcookie == null)
               m_Authcookie =
               Utilities.TranslateCookie(
                  HttpContext.Current.Request.Cookies[Utilities.CustomAuthCookieName]);
            return m_Authcookie;
         }
         set
         {
            m_Authcookie = value;
         }
      }
      private Cookie m_Authcookie = null;
   }

   [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
   internal sealed class Utilities
   {
      internal static string CustomAuthCookieName
      {
         get
         {
            lock (m_cookieNamelockRoot)
            {
               return m_cookieName;
            }
         }
         set
         {
            lock (m_cookieNamelockRoot)
            {
               m_cookieName = value;
            }
         }
      }

private static string m_cookieName;
      private static object m_cookieNamelockRoot = new object();

      private static HttpCookie TranslateCookie(Cookie netCookie)
      {
         if (netCookie == null)
            return null;
         HttpCookie webCookie = new HttpCookie(netCookie.Name, netCookie.Value);
         // Add domain only if it is dotted - IE doesn't send back the cookie 
         // if we set the domain otherwise
         if (netCookie.Domain.IndexOf('.') != -1)
            webCookie.Domain = netCookie.Domain;
         webCookie.Expires = netCookie.Expires;
         webCookie.Path = netCookie.Path;
         webCookie.Secure = netCookie.Secure;
         return webCookie;
      }

      internal static Cookie TranslateCookie(HttpCookie webCookie)
      {
         if (webCookie == null)
            return null;
         Cookie netCookie = new Cookie(webCookie.Name, webCookie.Value);
         if (webCookie.Domain == null)
            netCookie.Domain =
               HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
         netCookie.Expires = webCookie.Expires;
         netCookie.Path = webCookie.Path;
         netCookie.Secure = webCookie.Secure;
         return netCookie;
      }

      internal static void RelayCookieToClient(Cookie cookie)
      {
         // add the cookie if not already in there
         if (HttpContext.Current.Response.Cookies[cookie.Name] == null)
         {
            HttpContext.Current.Response.Cookies.Remove(cookie.Name);
         }

         HttpContext.Current.Response.SetCookie(TranslateCookie(cookie));
      }
   }

一些想法(1)是的,我会包括一个代码片段,以及任何其他配置(2)“正如你可能已经知道的”->我假设,我们可能还不知道,特别是考虑到下一点(3)“自定义安全扩展”-你能确保它正常工作吗?如果与.dll相同,为什么不获取源代码?(4)假设这不容易,你知道失败发生在哪里吗?日志等?我添加了一个代码片段供查看。我确实可以访问自定义安全扩展的源代码。我查看了SSR生成的日志,其中没有显示错误或失败。这就是为什么我想知道是否有一种方法可以将自定义安全扩展(即dll)置于调试模式,以便我可以逐步完成代码。是的,尽管您需要构建.dll的调试版本。这些是针对VS的,但对于可视代码应该是相同的:确保在开始调试之前构建DLL的调试版本。要调试DLL,调用应用程序必须能够找到它的.pdb文件和DLL所需的任何其他文件。一些想法(1)是的,我会包括一个代码段和任何其他配置(2)“正如你可能已经知道的”->我想,我们可能还不知道,特别是考虑到下一点(3)“自定义安全扩展”-您能否确保其工作正常?如果与.dll相同,为什么不获取源代码?(4)假设这不容易,你知道失败发生在哪里吗?日志等?我添加了一个代码片段供查看。我确实可以访问自定义安全扩展的源代码。我查看了SSR生成的日志,其中没有显示错误或失败。这就是为什么我想知道是否有一种方法可以将自定义安全扩展(即dll)置于调试模式,以便我可以逐步完成代码。是的,尽管您需要构建.dll的调试版本。这些是针对VS的,但对于可视代码应该是相同的:确保在开始调试之前构建DLL的调试版本。要调试DLL,调用应用程序必须能够找到其.pdb文件以及DLL所需的任何其他文件。