我在设置 WCF 服务与 Sharepoint Web 服务通信时遇到了很多困难,特别是我尝试使用 Lists.asmx 和 Copy.asmx 服务。
我使用 http 链接到共享点进行开发,但现在我们需要切换到 HTTPS 链接。我获得了网络参考设置并更新了此链接,但是当它尝试调用服务(例如: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>
如果有人知道我是否为 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 链接(到 sharepoint 的现有 HTTP 链接暂时仍然可以访问,直到我可以让服务与 HTTPS 链接一起工作) ).
确保指定用户可以通过浏览器访问 ASMX。
确保用户(至少)拥有目标库的读取权限。
另外,请确保用户具有
Use Remote Interfaces
权限(WSS 3.0:站点设置、高级权限、设置 - 权限级别,选择相应的权限级别)。
此外,如果您使用 MOSS 2007,可以在中央管理中禁用 SOAP 访问。
我目前没有可用的 Sharepoint 2010,因此无法检查,但我希望设置是对应的。
编辑:
如果在正常 HTTP 下一切正常,我会看看 HTTPS 的启用方式。
查看此网站“如何在 SharePoint 2010 Web 应用程序上启用 SSL”,尤其是第二部分(大约页面的 1/3,关于添加备用访问映射)。
希望这有帮助。
您收到此错误是因为您没有指定 mexHttpBinding 也使用“NewBinding0”绑定配置。发生的情况是,在实际 WCF 服务调用之前,WCF 正在尝试获取有关该服务的一些信息。如果该请求不将任何客户端凭据信息传输到服务,则该请求将会失败,因为它是安全的,并且您将收到来自服务器的 401 响应(未授权)。确保您的 mexHttpBinding 也发送 NTLM 凭据。
您也可以删除 mexHttpBinding