调用lists.asmx获取'http请求未经授权使用客户端身份验证方案'ntlm'

时间:2009-10-20 17:05:08

标签: c# sharepoint kerberos web-services

使用C#中的控制台应用程序调用lists.asmx获取 'http请求未经授权使用clien tuthentication scheme'ntlm'。从服务器收到的身份验证标头是“Negotiate,NTLM”。

环境:

  • Kerberos开启QA&制作,不是在开发中(我知道这很愚蠢,但我没有管理任何方框)
  • 使用sharepoint webservice从共享点列表(lists.asmx)获取GET数据。
  • 服务器使用ssl。

我在qa环境中收到如下错误消息(无法粘贴堆栈跟踪,因为它只在图片中):

System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'Negotiate,NTLM'. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.

直接导航到列表可以在每台机器上正常工作。

  • 代码在没有启用kerberos的开发环境(在服务器上)工作(应该是,但不是。我不能改变它。)
  • 代码适用于启用了kerberos的桌面计算机的生产
  • 代码在启用了kerberos的QA环境中不起作用。这是我收到错误的地方

要调用webservice,我这样做(不涉及其他与安全相关的代码)

XmlElement element = this.LIstsServiceClient.GetListItems(listName, '', query, fields, '300', null, null);

我的app.config如下

    <configuration>
    <system.serviceModel>
      <behaviors>
        <endpointBehaviors>
          <behavior name="clientEndpointBehavior">
            <clientCredentials>
              <windows allowedImpersonationLevel="Delegation"/>
            </clientCredentials>
          </behavior>
        </endpointBehaviors>
      </behaviors>
      <bindings>
            <basicHttpBinding>
                <binding name="ListsSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="999999999" maxBufferPoolSize="524288" maxReceivedMessageSize="999999999"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="999999" maxNameTableCharCount="16384" />
                    <security mode="Transport">
                      <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" realm="" />
                      <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
</basicHttpBinding>
<client>
         <endpoint address="https://servername/sitecollectionname/_vti_bin/Lists.asmx"
              binding="basicHttpBinding" bindingConfiguration="ListsSoap"
              contract="ListsService.ListsSoap" name="ListsSoap" behaviorConfiguration="clientEndpointBehavior"  >
            <identity>
              <servicePrincipalName value="spn" />
            </identity>
          </endpoint>
</client>
    </system.serviceModel>
</configuration>

5 个答案:

答案 0 :(得分:2)

看看here

启用匿名访问(域用户的用户名和密码) 启用集成Windows身份验证

或者,正如lextm-MSFT所说,检查您是否传递了一组有效的用户凭证

答案 1 :(得分:1)

我解决了问题:

这是Config

<system.serviceModel>
    <bindings />
    <client />
</system.serviceModel>

答案 2 :(得分:0)

这只是一种身份验证失败。检查您的控制台应用程序是否向承载此Web服务的IIS发送有效的用户凭据。

答案 3 :(得分:0)

我从未设法找到答案,但主要是因为我无法访问一致配置的环境,因此我无法调试我的代码。我认为这个问题是配置问题,可能与Kerberos有关。

答案 4 :(得分:0)

我通过允许在客户端端点上进行模拟来解决这个问题,Lists服务似乎要求它接收的第一个请求(可能取决于您正在调用的Web方法)。列表服务将令人困惑地在内部执行身份验证和验证,如果失败,则生成401或500响应,这使得看起来您的请求在访问服务之前在IIS中失败,而实际上,服务方法正在执行并返回错误

<behaviors>
   <endpointBehaviors>
      <behavior name="SPServiceBehavior">
          <clientCredentials>
                <windows allowedImpersonationLevel="Impersonation" allowNtlm="True"/>
          </clientCredentials>
      </behavior>
   </endpointBehaviors>
</behaviors>

See my question here for all the details.