WinForms ReportViewer не может подключиться к удаленному серверу отчетов (SQL Express) - PullRequest
1 голос
/ 24 января 2012

Введение:

У меня установлен SQL Server Express 2008 R2 с расширенными службами.Я создал несколько отчетов с использованием BI Design Studio и развернул их на сервере.Если я получаю доступ к серверу отчетов через IE (http://Ser2008/Reports/), он работает нормально (я должен ввести имя пользователя / пароль). Я могу просматривать отчеты или дурачиться с настройками.

Проблема:

На своем локальном компьютере я создал приложение 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();

Я получаю следующее исключение:

The attempt to connect to the report server failed.  Check your connection 
information and that the report server is a compatible version. The request 
failed with HTTP status 404: Not Found.

Трассировка стека выглядит следующим образом:

    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()

CustomCredentials:

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)

Ответы [ 2 ]

4 голосов
/ 24 января 2012

В конце концов, все это было тривиальной деталью 8 -)

Я использовал Report Manager URL (http://ser2008/Reports/), где я должен был использовать Report Server URL (http://ser2008/ReportServerXp/).

)
0 голосов
/ 12 июля 2012

Ну, вы должны реализовать 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;
    }

}

затем используйте это следующим образом:

IReportServerCredentials irsc = new CustomReportCredentials(userid,password, domain);
ReportViewer1.ServerReport.ReportServerCredentials = irsc;

другой код для установки свойства ServerReport опустить. надеюсь, у тебя будет хороший день.

...