Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reporting services WinForms ReportViewer无法连接到远程报表服务器(SQL Express)_Reporting Services_Ssrs 2008_Report Viewer2010 - Fatal编程技术网

Reporting services WinForms ReportViewer无法连接到远程报表服务器(SQL Express)

Reporting services WinForms ReportViewer无法连接到远程报表服务器(SQL Express),reporting-services,ssrs-2008,report-viewer2010,Reporting Services,Ssrs 2008,Report Viewer2010,简介: public class CustomCredentials : IReportServerCredentials { public string UserName { get; set; } public SecureString Password { get; set; } public string Domain { get; set; } #region ctor public CustomCredentials(string passw

简介:

public class CustomCredentials : IReportServerCredentials
{
    public string UserName { get; set; }
    public SecureString Password { get; set; }
    public string Domain { get; set; }

    #region ctor
    public CustomCredentials(string password)
    {
        Password = new SecureString();
        foreach (char c in password.ToCharArray())
            Password.AppendChar(c);
    }
    #endregion

    #region IReportServerCredentials Members
    public bool GetFormsCredentials(out Cookie authCookie, out string userName
                    , out string password, out string authority)
    {
        throw new NotImplementedException();
    }

    public System.Security.Principal.WindowsIdentity ImpersonationUser
    {
        get { throw new NotImplementedException(); }
    }

    public System.Net.ICredentials NetworkCredentials
    {
        get { return new NetworkCredential(UserName, Password, Domain); }
    }
    #endregion
}
我已经安装了SQL Server Express 2008 R2和高级服务。我使用BI Design Studio创建了一些报告,并将它们部署到服务器上。如果我使用IE访问报表服务器(http://Ser2008/Reports/)它工作正常(我必须输入用户名/密码)。我可以查看报告,也可以随意设置

问题:

public class CustomCredentials : IReportServerCredentials
{
    public string UserName { get; set; }
    public SecureString Password { get; set; }
    public string Domain { get; set; }

    #region ctor
    public CustomCredentials(string password)
    {
        Password = new SecureString();
        foreach (char c in password.ToCharArray())
            Password.AppendChar(c);
    }
    #endregion

    #region IReportServerCredentials Members
    public bool GetFormsCredentials(out Cookie authCookie, out string userName
                    , out string password, out string authority)
    {
        throw new NotImplementedException();
    }

    public System.Security.Principal.WindowsIdentity ImpersonationUser
    {
        get { throw new NotImplementedException(); }
    }

    public System.Net.ICredentials NetworkCredentials
    {
        get { return new NetworkCredential(UserName, Password, Domain); }
    }
    #endregion
}
在本地计算机上,我创建了一个winforms应用程序,其中一个窗体包含ReportViewer控件。在表单加载时,我运行以下代码:

reportViewer1.ProcessingMode = ProcessingMode.Remote;
reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials = 
            new CustomCredentials("secret@123") { 
                          UserName = "administrator", 
                          Domain = "ser2008" 
            }.NetworkCredentials;

reportViewer1.ServerReport.ReportServerUrl = new Uri("http://ser2008/Reports/");
reportViewer1.ServerReport.ReportPath = "/Students/Attendance";

var l = new List<ReportParameter>();
l.Add(CreateParameter("UserId", "144"));
l.Add(CreateParameter("Class", "8"));
l.Add(CreateParameter("date_from", "2011-09-04"));
l.Add(CreateParameter("date_to", "2011-12-31"));

reportViewer1.ServerReport.SetParameters(l); //EXCEPTION THROWN HERE
reportViewer1.RefreshReport();
堆栈跟踪如下所示:

    at Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005
                .Execution.RSExecutionConnection.MissingEndpointException
                .ThrowIfEndpointMissing(WebException e)
at Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005
                .Execution.RSExecutionConnection.ProxyMethodInvocation.Execute[TReturn]
                      (RSExecutionConnection connection, ProxyMethod`1 initialMethod, ProxyMethod`1 retryMethod)
at Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005.
                Execution.RSExecutionConnection.LogonUser(String userName, String password, String authority)
at Microsoft.Reporting.WinForms.ServerReport.get_Service()
at Microsoft.Reporting.WinForms.ServerReport.EnsureExecutionSession()
at Microsoft.Reporting.WinForms.ServerReport.SetParameters(IEnumerable`1 parameters)
at GridEditor.ReportViewerForm.btnRefresh_Click(Object sender, EventArgs e) 
                in D:\TestApp\ReportViewerForm.cs:line 79
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager
                        .FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at GridEditor.Program.Main() in D:\TestApp\Program.cs:line 16
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback
                        , Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
IReportServerCredentials irsc = new CustomReportCredentials(userid,password, domain);
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
客户凭证:

public class CustomCredentials : IReportServerCredentials
{
    public string UserName { get; set; }
    public SecureString Password { get; set; }
    public string Domain { get; set; }

    #region ctor
    public CustomCredentials(string password)
    {
        Password = new SecureString();
        foreach (char c in password.ToCharArray())
            Password.AppendChar(c);
    }
    #endregion

    #region IReportServerCredentials Members
    public bool GetFormsCredentials(out Cookie authCookie, out string userName
                    , out string password, out string authority)
    {
        throw new NotImplementedException();
    }

    public System.Security.Principal.WindowsIdentity ImpersonationUser
    {
        get { throw new NotImplementedException(); }
    }

    public System.Net.ICredentials NetworkCredentials
    {
        get { return new NetworkCredential(UserName, Password, Domain); }
    }
    #endregion
}
更新:

public class CustomCredentials : IReportServerCredentials
{
    public string UserName { get; set; }
    public SecureString Password { get; set; }
    public string Domain { get; set; }

    #region ctor
    public CustomCredentials(string password)
    {
        Password = new SecureString();
        foreach (char c in password.ToCharArray())
            Password.AppendChar(c);
    }
    #endregion

    #region IReportServerCredentials Members
    public bool GetFormsCredentials(out Cookie authCookie, out string userName
                    , out string password, out string authority)
    {
        throw new NotImplementedException();
    }

    public System.Security.Principal.WindowsIdentity ImpersonationUser
    {
        get { throw new NotImplementedException(); }
    }

    public System.Net.ICredentials NetworkCredentials
    {
        get { return new NetworkCredential(UserName, Password, Domain); }
    }
    #endregion
}
我在日志文件的某个位置也发现了以下异常:

System.Web.Services.Protocols.SoapException: The path of the item 
'/Students/Attendance/_vti_bin/ListData.svc/$metadata' is not valid. The full 
path must be less than 260 characters long; other restrictions apply. If the 
report server is in native mode, the path must start with slash. ---> 
Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException:
The path of the item '/Students/Attendance/_vti_bin/ListData.svc/$metadata' is 
  not valid. The full path must be less than 260 characters long; other 
  restrictions apply. If the report server is in native mode, the path must 
  start with slash.
at Microsoft.ReportingServices.WebServer.ReportingService2005Impl
      .GetPermissions(String Item, String[]& Permissions)

最后都是琐碎的细节8-)


我使用的是
报表管理器
url(http://ser2008/Reports/)我将在哪里使用
报表服务器
url(http://ser2008/ReportServerXp/).

好的,您应该实现
IReportServerCredential
,代码示例如下:

public class CustomReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
{  

    // local variable for network credential.
    private string _UserName;
    private string _PassWord;
    private string _DomainName;
    public CustomReportCredentials(string UserName, string PassWord, string DomainName)
    {  
        _UserName = UserName;
        _PassWord = PassWord;
        _DomainName = DomainName; 
    }
    public WindowsIdentity ImpersonationUser
    {
        get
        { 
            return null;  // not use ImpersonationUser
        }
    }
    public ICredentials NetworkCredentials
    {
        get
        { 

           // use NetworkCredentials
            return new NetworkCredential(_UserName,_PassWord,_DomainName);
        }
    }
    public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
    { 

       // not use FormsCredentials unless you have implements a custom autentication.
        authCookie = null;
        user = password = authority = null;
        return false;
    }

}
然后按如下方式使用:

    at Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005
                .Execution.RSExecutionConnection.MissingEndpointException
                .ThrowIfEndpointMissing(WebException e)
at Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005
                .Execution.RSExecutionConnection.ProxyMethodInvocation.Execute[TReturn]
                      (RSExecutionConnection connection, ProxyMethod`1 initialMethod, ProxyMethod`1 retryMethod)
at Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005.
                Execution.RSExecutionConnection.LogonUser(String userName, String password, String authority)
at Microsoft.Reporting.WinForms.ServerReport.get_Service()
at Microsoft.Reporting.WinForms.ServerReport.EnsureExecutionSession()
at Microsoft.Reporting.WinForms.ServerReport.SetParameters(IEnumerable`1 parameters)
at GridEditor.ReportViewerForm.btnRefresh_Click(Object sender, EventArgs e) 
                in D:\TestApp\ReportViewerForm.cs:line 79
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager
                        .FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at GridEditor.Program.Main() in D:\TestApp\Program.cs:line 16
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback
                        , Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
IReportServerCredentials irsc = new CustomReportCredentials(userid,password, domain);
ReportViewer1.ServerReport.ReportServerCredentials = irsc;

用于设置ServerReport属性的其他代码忽略。祝您度过愉快的一天。

ReportViewer1.ServerReport.ReportServerCredentials
在winforms中是只读的。