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