【问题标题】:ReportingService2005 via WCF - works with impersonation, but not with username/password通过 WCF 的 ReportingService2005 - 适用于模拟,但不适用于用户名/密码
【发布时间】:2011-09-12 15:29:30
【问题描述】:

我正在通过 WCF 连接到 SSRS 2008 的 ReportingService2005 服务。

我让它与模拟一起工作,像这样:

ReportingService2005SoapClient rService = 
    new ReportingService2005SoapClient("endpoint config name", "the url");
rService.ClientCredentials.Windows.AllowedImpersonationLevel =
    System.Security.Principal.TokenImpersonationLevel.Impersonation;
rService.ChannelFactory.Credentials.Windows.ClientCredential =
    CredentialCache.DefaultNetworkCredentials;

但是当我尝试将特定的用户名/密码传递给它时,就像这样:

rService.ChannelFactory.Credentials.Windows.ClientCredential = 
    new NetworkCredential(username, password, domain); 

我在第一次方法调用时收到此错误:

HTTP 请求未经客户端身份验证方案授权 'Ntlm'。从服务器收到的身份验证标头是“NTLM”。

这是我的 wcf 绑定配置的相关部分:

<basicHttpBinding>
    <binding name="ReportingService2005Soap"  ... blah blah blah ...
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
          maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>

我对在两种不同情况下提到 Ntlm 的错误消息感到困惑。

所以问题是 - 我需要调整两个不同的 WCF 设置中的哪一个才能使其正常工作? :)

编辑:这是来自 SSRS 服务器的 RSReportServer.config 的身份验证位:

<Authentication>
    <AuthenticationTypes>
        <RSWindowsNegotiate/>
        <RSWindowsNTLM/>
    </AuthenticationTypes>
    <EnableAuthPersistence>true</EnableAuthPersistence>
</Authentication>

并来自 SSRS web.config:

<authentication mode="Windows" />

编辑:我将标记迄今为止最好的答案,但这仍然是开放的,因为我还没有找到让我在代码中设置任意凭据的解决方案。

【问题讨论】:

  • 错误消息表明这可能只是一个大小写问题 - 您是否尝试修改绑定以使用 clientCredentialType="NTLM" proxyCredentialType="NTLM"
  • @Ed:是的,试过了。如果我使用大写字母,则会收到错误“无法解析属性 'clientCredentialType' 的值。”

标签: c# sql-server wcf reporting-services credentials


【解决方案1】:

好的,新的尝试。

WCF 服务运行在 IIS 中,SSRS 使用 windows 身份验证。

当您进行 Windows 身份验证时,它可以工作,因为使用了用户的 Windows 安全上下文。

当您使用用户名和密码时,使用的是 IIS 用户。无权访问 SSRS。

所以要让它工作:

  • 在 WCF 服务 web.config 的安全部分设置 impersonate=false。
  • 这将强制它使用应用程序池的身份
  • 然后将应用程序池的身份更改为有权访问 SSRS 的用户

【讨论】:

  • 是的,我认为它设置为 Windows 身份验证。我认为仍然可以作为固定用户登录它(例如,ASP.NET ReportViewer 组件能够这样做)
  • 想想看,SSRS 2008 不使用 IIS。
  • 谢谢,您的应用程序池建议有效。这解决了我的直接问题,但表明我不能在代码中设置任意凭据。也就是说,我只能选择模拟或应用程序池身份。
  • 我没有关注您的应用程序池建议。由于我们在 SSRS 而不是 IIS 中,因此我们没有应用程序池。如果它不存在,你如何设置它的身份?
【解决方案2】:

通过指定绕过它:

client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

【讨论】:

    【解决方案3】:

    请将您的传输元素属性值更改为:

    <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
    

    希望对您有所帮助...

    【讨论】:

    • 然后我得到一个稍微不同的错误:“HTTP 请求未经授权,使用客户端身份验证方案'Negotiate'。从服务器收到的身份验证标头是'Negotiate'。
    • 你的客户端和SSRS服务器是在同一个域还是域有信任关系?
    • 能否添加:client.ClientCredentials.Windows.AllowNTLM = True
    • :没有任何区别。感谢您的建议
    • 我好奇怪,握手协议没问题,但是好像没有开始用户认证。如果这会启动,我希望看到另一条错误消息。初级,问题是:系统上缓存的凭据与显式创建新凭据之间有什么区别。那不应该是火箭科学。但是,它不适用于您的情况。可以提议用Wireshark上线,看看工作和不工作情况下的握手区别?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多