使用WCF设置NTLM身份验证到Sharepoint Web服务

Pvp*_*n22 6 c# https sharepoint wcf ntlm

设置我的WCF服务以与Sharepoint Web服务进行通信时遇到了很多困难,特别是我正在尝试使用Lists.asmx和Copy.asmx服务.

我使用http链接到sharepoint进行开发,但现在我们需要切换到HTTPS链接.我获得了Web引用设置并更新了此链接,但是当它尝试调用服务(例如:GetListItems)时,它出错并出现以下错误:请求失败,HTTP状态为401:未经授权.

然后我试着看看我们的Sharepoint Server使用什么类型的身份验证,结果证明是NTLM.然后我尝试为此配置web.config文件.这是整个web.config文件:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="InventoryService.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
        </sectionGroup>
    </configSections>
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
        </compilation>
        <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
        <authentication mode="Windows"/>
        <!--
        The <customErrors> section enables configuration 
        of what to do if/when an unhandled error occurs 
        during the execution of a request. Specifically, 
        it enables developers to configure html error pages 
        to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
         <error statusCode="403" redirect="NoAccess.htm" />
         <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
    -->
        <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
    <!-- 
      The system.webServer section is required for running ASP.NET AJAX under Internet
      Information Services 7.0.  It is not necessary for previous version of IIS.
  -->
    <system.serviceModel>
        <bindings>
   <basicHttpBinding>
    <binding name="NewBinding0">
     <security mode="TransportCredentialOnly">
      <transport clientCredentialType="Ntlm" proxyCredentialType="None" />
     </security>
    </binding>
   </basicHttpBinding>
  </bindings>
  <services>
   <service behaviorConfiguration="InventoryService.Service1Behavior"
    name="InventoryService.InventoryService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
     contract="InventoryService.IInventoryService">
     <identity>
      <dns value="localhost" />
     </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>
  </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="InventoryService.Service1Behavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>
    <applicationSettings>
        <InventoryService.Properties.Settings>
   <setting name="InventoryService_WSCopy_Copy" serializeAs="String">
    <value>http://site/_vti_bin/Copy.asmx</value>
   </setting>
   <setting name="InventoryService_SharepointLists_Lists" serializeAs="String">
    <value>https://site/_vti_bin/Lists.asmx</value>
   </setting>
  </InventoryService.Properties.Settings>
    </applicationSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如果我有一个线索,如果我正确地为NTLM设置此配置文件,这将是非常有帮助的.

如果设置正确,那么我想我会继续讨论是否正确设置凭据的下一个问题:

inventoryList = new SharepointLists.Lists();
inventoryList.Url = "https://fullsiteurl/_vti_bin/Lists.asmx";
inventoryList.Credentials = new System.Net.NetworkCredential("user", "pass", "domain");
Run Code Online (Sandbox Code Playgroud)

如果有人能够解决这个问题,那也会非常有帮助.

我再次知道配置文件很长,如果你仔细阅读它我非常感谢它让我知道我是否正确设置了NTLM身份验证.

如果所有这些检查都没问题,那么我不知道从哪里开始获得带有sharepoint的HTTPS链接(现在仍然可以访问到sharepoint的现有HTTP链接,直到我可以使用HTTPS链接获得服务) .

Sam*_*m B 0

确保指定用户可以使用浏览器访问 ASMX。

确保用户(至少)具有目标库的读取权限。

另外,请确保用户具有Use Remote Interfaces权限(WSS 3.0:站点设置,高级权限,设置-权限级别,选择相应的权限级别)。

另外,如果您使用的是 MOSS 2007,则可以在中央管理中禁用 SOAP 访问。

我目前没有可用的 Sharepoint 2010,因此无法检查,但我希望设置是对应的。

编辑

如果在正常 HTTP 下一切正常,我会看看 HTTPS 的启用方式。

请查看此网站“如何在 SharePoint 2010 Web 应用程序上启用 SSL ”,特别是第二部分(大约页面的 1/3,关于添加备用访问映射)。

希望这可以帮助。