我試圖通過ASP.NET網頁ReportViewer控件連接到ReportingServices:引發WebException使用的ReportViewer
rvContract.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
rvContract.ServerReport.ReportServerCredentials = new ReportServerCredentials("myUsername", "myNetworkPassword", "DOMAIN");
rvContract.ServerReport.ReportServerUrl = new Uri(ReportConfiguration.ReportServerUrl);
string rptPath = ReportConfiguration.RootPath;
if (!rptPath.EndsWith("/"))
{
rptPath += "/";
}
rvContract.ServerReport.ReportPath = rptPath + "AdminReports/Contract";
List<ReportParameter> reportParams = new List<ReportParameter>();
if (MkoSession.AccountId.HasValue)
{
ReportParameter accountId = new ReportParameter("AccountId", MkoSession.AccountId.Value.ToString());
}
rvContract.ServerReport.SetParameters(reportParams);
rvContract.ShowParameterPrompts = false;
rvContract.ShowZoomControl = false;
rvContract.ServerReport.Refresh();
rvContract.DataBind();
憑據的實現看起來是這樣的:
public class ReportServerCredentials : IReportServerCredentials
{
private string _userName;
private string _password;
private string _domain;
public ReportServerCredentials(string userName, string password, string domain)
{
_userName = userName;
_password = password;
_domain = domain;
}
public WindowsIdentity ImpersonationUser
{
get
{
// Use default identity.
return null;
}
}
public ICredentials NetworkCredentials
{
get
{
// Use default identity.
return new NetworkCredential(_userName, _password, _domain);
}
}
public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
{
// Do not use forms credentials to authenticate.
authCookie = null;
user = null;
password = null;
authority = null;
return false;
}
}
只是硬編碼我的憑據,而測試。在辦理登機手續前,我們必須爲此創建一個域帳戶。
我可以通過瀏覽器訪問ReportService2005.asmx和ReportExecution2005.asmx(這是我的ReportServerUrl變成)沒有問題。
當我到達SetParameters調用時,我得到一個WebException。看着異常內響應頭:
{RSNotAuthenticated:真 RSAuthenticationHeader:.ASPXFORMSAUTH 的Content-Length:206 緩存控制:私人 的Content-Type:text/html的; charset = utf-8 日期:2013-09-09 16:15:08 GMT 位置:/ReportServer/logon.aspx?ReturnUrl=%2freportserver%2fReportExecution2005.asmx 服務器:Microsoft-HTTPAPI/2.0 X-AspNet-版本:2.0.50727
}
這好像是在告訴我,我還沒有登錄。如果是這樣的話,該怎麼辦完全相同的憑據允許通過我看到了Web服務。一個瀏覽器?
順便說一句,我沒有在我的ReportServerCredentials實現中的每個方法中設置斷點,並看到每個斷點。不知道這是告訴我們什麼,但NetworkCredentials界面很好地返回了我的網絡憑據。