SSRS Web服务访问异常 - 401未授权方案'Ntlm'

时间:2013-06-08 21:01:06

标签: asp.net reporting-services ssrs-2008

我已经花了一天时间来处理以下.NET framework 4.0异常。我已经在线研究过解决方案,但我还没有找到合适的解决方案。 请提前帮助和感谢。

我的asp.net Web应用程序在我的本地PC环境中运行正常同时具有IIS 8.0和本地SQL Server 2012实例,但是 异常上升当我将其部署到具有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 Reporting Service的SOAP Web服务(请参阅http://msdn.microsoft.com/en-us/library/ee640743.aspx)。 我的asp.net Web表单解决方案名为“MyAspNetSolution”,是使用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服务的端点,绑定和部分的部分如下所示:

...
 <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>
...  

P / S:

我还查看了以下线程(对于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

1 个答案:

答案 0 :(得分:1)

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

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

由于