gpt4 book ai didi

asp.net - SSRS Web 服务访问异常 - 401 未经授权的方案 'Ntlm'

转载 作者:行者123 更新时间:2023-12-02 15:30:07 24 4
gpt4 key购买 nike

我已经花了一个工作日来处理以下 .NET Framework 4.0 异常。我在网上研究了解决方案,但还没有找到可行的解决方案。请提前提供帮助并致谢。

我的 asp.net Web 应用程序在我的本地 PC 环境上运行正常,该环境同时具有 IIS 8.0 和本地 SQL Server 2012 实例,但是当我将其部署到同时具有 IIS 8.0 和 SQL Server 2012 实例的 Web 服务器时,出现异常。

异常(exception):

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 表单应用程序,它具有对 SQL Server 2012 Reporting Service 的 SOAP Web 服务的 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”的类库项目,其 Web 引用为并使用 SSRS SOAP 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 Reporting Service 的 SOAP Web 服务的端点、绑定(bind)和其他部分如下所示:

...
<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 services -- The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'

或其他资源:

http://jaliyaudagedara.blogspot.com/2012/05/accessing-report-server-using-report.html

最佳答案

您应该尝试 NetworkCredentials 并将它们传递给客户端。如果仍然出现错误,请将其放入您的 wcf 配置文件中:

<identity>
<servicePrincipalName value=""/>
</identity>

谢谢

关于asp.net - SSRS Web 服务访问异常 - 401 未经授权的方案 'Ntlm',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17003807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com