0

我有一个简单的 .NET WPF 应用程序。我添加了服务参考。到

//服务器:端口/站点/site_collection_name/_vti_bin/lists.asmx

并将其称为 ListServ。我输入了以下代码

       ListsSoapClient client = new ListsSoapClient();
       if (client.ClientCredentials != null)
       client.ClientCredentials.Windows.AllowedImpersonationLevel =   System.Security.Principal.TokenImpersonationLevel.Impersonation;         

       try
       {
               client.Open();
               Console.WriteLine(client.State);
               System.Xml.Linq.XElement listCollection = client.GetListCollection();
       }
}

从 app.config

          <binding name="ListsSoap">
            <security mode="TransportCredentialOnly">
              <transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"
                  realm="" />
              <message clientCredentialType="UserName" algorithmSuite="Default" />
            </security>
          </binding>

上面的代码捕获了 CommunicationException:

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) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication
   HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)

我已经在共享点所在的 ISS 上启用了 Windows autentication。非常奇怪的是,我使用类似的代码成功地将文档添加到文档库。所有凭证都正确描述了在共享点列表中添加的文档。

我什至尝试过弃用:client.ClientCredentials.Windows.AllowNtlm = true;

4

2 回答 2

0

If you're trying to call this web service from another farm, you're going to run into the double hop issue, explained here. Basically, NTLM has no way of knowing what a SharePoint user's windows credentials are. You can get around this by:

  • hardcoding credentials,
  • allowing anonymous access, or
  • setting up Kerberos authentication.
于 2013-05-22T19:14:01.480 回答
0

I replaced Service Reference with Web Reference and it works.

于 2013-05-23T10:35:14.673 回答