使用C#中的控制台应用程序调用lists.asmx获取 'http请求未经授权使用clien tuthentication scheme'ntlm'。从服务器收到的身份验证标头是“Negotiate,NTLM”。
环境:
我在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.
直接导航到列表可以在每台机器上正常工作。
要调用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>
答案 0 :(得分:2)
答案 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>