【问题标题】:Sharepoint 2010 Custom Web Service - The HTTP request is unauthorized with client authentication scheme 'Ntlm'Sharepoint 2010 自定义 Web 服务 - HTTP 请求未经客户端身份验证方案“Ntlm”授权
【发布时间】:2011-03-01 17:03:43
【问题描述】:

我有两个基于 SharePoint 构建的自定义 Web 服务。我们在周末切换了服务器并将站点从 2008 年升级到 2010 年。现在,当通过 .NET Web 服务包装器查看时,每个 Web 服务都会出现以下错误。

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

System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

Web 服务的 dll 位于 GAC 中,ASMX 文件位于 LAYOUTS hive 文件夹中。这些在升级/服务器移动之前运行良好。

认为正在发生的事情是默认的 Windows 凭据没有被传递给服务。我的 Web 服务调用 SharePoint Web 服务来获取列表内容。

这是一个返回 401 的调用示例:

<WebMethod()> _
Public Function TestGetUserInfo() As String
    Dim userService As New SharepointUser.UserGroup
    userService.Credentials = System.Net.CredentialCache.DefaultCredentials

    Dim UserInfoXML As XmlNode = userService.GetUserInfo(User.Identity.Name)

    Return UserInfoXML.ChildNodes(0).Attributes("Name").Value
End Function

此调用违反:http://{DomainName}/_vti_bin/Lists.asmx?wsdl

我已验证 user.identity.name 返回正确的登录用户信息。我认为是 system.net.credentialcahche.defaultcredentials 不起作用。我也试过 .defaultnetworkcredentials 没有运气。

这就是我在 web.config 中的内容:

  <system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<bindings>
  <basicHttpBinding>
    <binding name="projectBasicHttpConf" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="true" maxBufferSize="4194304" maxReceivedMessageSize="500000000" messageEncoding="Text" transferMode="StreamedResponse">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="BasicHttpBindingWithWindowsAuthentication">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Windows" proxyCredentialType="None" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="SPFilesAccessServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 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="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="clientEndPointBehavior">
      <clientCredentials>
        <windows allowedImpersonationLevel="Impersonation" />
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>

在system.web下:

<authentication mode="Windows" />
<identity impersonate="true" />

我在匿名身份验证中来回走动,没有运气。

在 IIS 中,我启用了 Windows 身份验证并将 NTLM 作为我的提供者。

关于如何解决这个问题的任何想法?非常感谢您的阅读。

-内特

【问题讨论】:

    标签: web-services iis-7 sharepoint-2010


    【解决方案1】:

    我从来没想过。我做了一个解决方法,我直接调用 Microsoft.Sharepoint 命名空间的东西,而不是调用 Web 服务。这绕过了安全问题。

    【讨论】:

    • 你能给我更多关于你的解决方案的细节吗?我也有错误“请求失败,HTTP 状态 401:未经授权”。谢谢
    • 问题是 sharepoint 不接受 web 服务传递的凭据。如果设置正确,它应该已经将用户的 windows 信息传递给 web 服务并使用它。在我的情况下,它使用的是像网络服务这样的服务帐户。我最终只使用了 sharepoint.dll 并进行了直接调用。
    【解决方案2】:

    您需要从客户端传递的只是 System.Net.NetworkCredentials("Username",Password","Domain");

    应该能解决我猜的问题。

    【讨论】:

      【解决方案3】:

      由于您使用服务器对象模型而不是 Web 服务调用(仅适用于服务器)解决了这个问题,这可能是导致 401 的环回检查功能。 这是 MS KB-http://support.microsoft.com/kb/896861

      建议使用指定主机方法而不是禁用注册表设置。

      【讨论】:

        猜你喜欢
        • 2011-06-22
        • 2013-10-29
        • 1970-01-01
        • 1970-01-01
        • 2012-04-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多