2011-04-22 167 views
6

我一直在設置我的WCF服務與Sharepoint Web服務交談時遇到了很多困難,特別是我試圖使用Lists.asmx和Copy.asmx服務。使用WCF設置NTLM身份驗證到Sharepoint Web服務

我知道它使用http鏈接來開發sharepoint,但現在我們需要切換到HTTPS鏈接。我得到了web參考設置並更新了這個鏈接,但是當它試圖調用一個服務(例如:GetListItems)時,它出錯並出現以下錯誤: HTTP狀態401請求失敗:未經授權。

然後我試着看看我們的Sharepoint服務器使用什麼類型的身份驗證,結果是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> 

如果任何人有一個線索,如果我設置此配置文件用於正確NTLM,這將是真正的幫助。

如果設置正確的話,我想我會繼續前進到下一個問題,如果我設置憑據正確:

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

如果有人能去了這一點,這也將是非常有益的。

我再次知道配置文件很長,我非常感謝它,如果你經歷它,讓我知道我是否正確設置NTLM身份驗證。

如果所有這些都檢查出好,那麼我不知道從哪裏開始獲取帶有Sharepoint的HTTPS鏈接工作(現有的HTTP Sharepoint鏈接暫時仍可訪問,直到我可以使用該服務HTTPS鏈接)。

+0

只是可以肯定,你有一個WCF服務,調用到SharePoint Web服務的權利?第一個問題:爲什麼你不直接在你的WCF服務中使用Sharepoint API?第二個問題:您是否能夠使用指定的用戶憑據在HTTPS中瀏覽SharePoint站點? – 2011-04-22 19:14:51

+0

是的,我正在使用一個WCF服務,通過對網站lists.asmx url使用Web引用來調用Sharepoint Web服務。 1.我無法使用Sharepoint API,因爲該服務不會與Sharepoint位於同一臺計算機上,所以Sharepoint API只有在與Sharepoint Server位於同一臺計算機上時纔可用。 2.是的,我的用戶憑證可以正常使用HTTPS鏈接,我也可以使用這些憑證添加Web引用。 – PvpMan22 2011-04-25 13:17:58

回答

0

確保指定的用戶可以通過瀏覽器訪問ASMX。

確保用戶具有(至少)對目標庫的讀取權限。

此外,請確保用戶有Use Remote Interfaces准予(WSS 3.0:網站設置,高級權限,設置 - 權限級別,選擇相應的權限級別)。

此外,如果您使用的是MOSS 2007,則可以在中央管理中禁用SOAP訪問。

我目前沒有Sharepoint 2010,所以我無法檢查,但我期望設置是相應的。

編輯

如果一切正常HTTP的偉大工程,我想看看是HTTPS啓用的方式。

看看這個網站「How to enable SSL on a SharePoint 2010 web application」,特別是第二部分(約1/3的頁面,關於添加替代訪問映射)。

希望這會有所幫助。

+0

如果它使用HTTP工作,這是否適用?當我將它引用到lists.asmx服務的HTTP鏈接時,我可以獲取並更新列表數據。當我嘗試使用HTTPS時會出現問題,即使使用有效憑據,它立即拒絕我訪問。所以我覺得我爲HTTPS鏈接設置了錯誤的安全性。 – PvpMan22 2011-04-26 14:17:42

0

由於您未指定mexHttpBinding也使用'NewBinding0'綁定配置,因此您收到此錯誤。發生什麼情況是,在實際的WCF服務調用之前,WCF正試圖獲取有關該服務的一些信息。如果它沒有將任何客戶端憑證信息傳輸到服務,該請求將失敗,因爲它是安全的,並且您將從服務器(未授權)接收401響應。確保你的mexHttpBinding也發送了NTLM證書。

你可以或者刪除mexHttpBinding