我试图通过在本地运行,从我的asp.net Web应用程序调用报告相关服务(asmx)。然后一个例外发生了。 The request failed with http status401:unauthorised
。
在我的分析中,我理解了由于以下代码引起的问题
SSRSWebService.ReportingService2005 rs = new SSRSWebService.ReportingService2005();
rs.Credentials = new MyReportServerCredentials().NetworkCredentials;
和
Uri reportUri = new Uri(ConfigurationManager.AppSettings["ReportServerManagement.ReportingService2005"]);
this.rptViewer.ServerReport.ReportServerCredentials = new MyReportServerCredentials();
在我的详细分析中,我了解到问题是由于在[[serviceObject.credential中设置的凭据,或者ServerReport.ReportServerCredentials错误。可以通过以下两种方式纠正此问题,方法是使用以下代码将凭据设置为默认值。rs.Credentials = System.Net.CredentialCache.DefaultCredentials;//"rs" is report object
或找到下面的代码,并在代码中设置正确的经过身份验证的用户凭证
public WindowsIdentity ImpersonationUser
{
get
{
// Use the default Windows user. Credentials will be
// provided by the NetworkCredentials property.
return null;
}
}
public ICredentials NetworkCredentials
{
get
{
// Read the user information from the Web.config file.
// By reading the information on demand instead of
// storing it, the credentials will not be stored in
// session, reducing the vulnerable surface area to the
// Web.config file, which can be secured with an ACL.
// User name
string userName =
<<AccurateUserName;>>
// Password
string password =
<<AccuratePassword;>>
// Domain
string domain = <<AccurateDomainName;>>
return new NetworkCredential(userName, password, domain);
}
}
为了检查哪个用户有权访问,我们需要在Web浏览器中键入以asmx结尾的服务URL()。它将提示用户名和密码。输入我们的用户名:Domain \ Username和密码。如果我们能够看到wsdl xml文件,则该用户具有访问权限。http:/MyServiceHostedServer/MyService.asmx