我已经为以下 .NET 框架 4.0 异常花费了一天的工作时间。我在网上研究了解决方案,但我还没有找到一个可行的解决方案。请提前帮助和感谢。
我的 asp.net Web 应用程序在具有 IIS 8.0 和本地 SQL Server 2012 实例的本地 PC 环境中运行良好,但是当我将其部署到同时具有 IIS 8.0 和 SQL Server 2012 实例的 Web 服务器时出现异常。
例外:
Stack Trace:
[WebException: The remote server returned an error: (401) Unauthorized.]
System.Net.HttpWebRequest.GetResponse() +8527180
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +237
[MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +14539490
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +622
MyAspNetSolution.Services.ReportService2010.ReportingService2010Soap.ListChildren(ListChildrenRequest request) +0
MyAspNetSolution.Services.ReportService2010.ReportingService2010SoapClient.MyAspNetSolution.Services.ReportService2010.ReportingService2010Soap.ListChildren(ListChildrenRequest request) +102
MyAspNetSolution.Services.ReportService2010.ReportingService2010SoapClient.ListChildren(TrustedUserHeader TrustedUserHeader, String ItemPath, Boolean Recursive, CatalogItem[]& CatalogItems) +220
MyAspNetSolution.Services.ReportServerInfoService.ListReportCollection(String itemPath, Boolean recursive) +653
MyAspNetSolution.AspxPageListAllReportsOnSSRS.Page_Load(Object sender, EventArgs e) +151
....
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034
详情/我的故事:
我有一个 asp.net Web 表单应用程序,它有一个 Web 引用并使用 SQL Server 2012 报告服务的 SOAP Web 服务(请参阅http://msdn.microsoft.com/en-us/library/ee640743.aspx)。我的名为“MyAspNetSolution”的asp.net Web 表单解决方案是使用VS 2012 / .NET framework 4.5 和本地企业版SQL Server 2012 开发的。该解决方案包含Web 表单应用程序项目和其他自定义类库项目。其中一个类库项目是一个名为“MyAspNetSolution.Services”的类库项目,它具有对 SSRS SOAP Web 服务的 Web 引用和使用,例如:
...
using MyAspNetSolution.Services.ReportService2010;
using System.Net;
...
namespace MyAspNetSolution.Services
{
public class ReportServerInfoService
{
public CatalogItem[] ListReportCollection(string itemPath, bool recursive)
{
CatalogItem[] reportCollection = {};
try
{
ReportService2010.ReportingService2010SoapClient client = new ReportService2010.ReportingService2010SoapClient();
client.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.Open();
TrustedUserHeader t = new TrustedUserHeader();
try
{
// I need to list of children of a specified folder.
client.ListChildren(t, itemPath, recursive, out reportCollection); // see http://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.listchildren.aspx
}
catch (SoapException ex)
{
_logger.Error("ReportServerManagementService--" + ex);
}
}
catch (SoapException ex)
{
_logger.Error("ReportServerManagementService--" + ex);
}
return reportCollection;
}
}
}
我的 Web 应用程序项目Web.config中 SQL Server 2012 报告服务的 SOAP Web 服务的端点、绑定和其他部分如下所示:
...
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="ReportingService2010Soap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://my-pc-network-domain-or-server-domain/ReportServer_SQL2012/ReportService2010.asmx" binding="basicHttpBinding" bindingConfiguration="ReportingService2010Soap" contract="ReportService2010.ReportingService2010Soap" name="ReportingService2010Soap"/>
</client>
</system.serviceModel>
...
附言:
我还查看了以下线程(用于 SharePoint 客户端开发),代码与我正在开发的代码(用于 SSRS 客户端开发)相同,但在我的本地 PC 环境中工作,而不是在 Web 服务器上。
Sharepoint Web 服务——HTTP 请求未经客户端身份验证方案“Ntlm”的授权。从服务器收到的身份验证标头是“NTLM”
或其他资源:
http://jaliyaudagedara.blogspot.com/2012/05/accessing-report-server-using-report.html