我正在编写一个简单的C#控制台应用程序,它将调用" Lists.asmx" SharePoint网站上的Web服务以下拉附件。我已经添加了服务引用并尝试运行它,但它失败并显示错误
未提供用户名。在ClientCredentials中指定用户名。
当它尝试对GetAttachmentCollection
进行服务方法调用时。以下是代码:
static void Main(string[] args)
{
ListsSoapClient client = new ListsSoapClient();
client.ClientCredentials.Windows.ClientCredential =
CredentialCache.DefaultNetworkCredentials;
XElement attachments = client.GetAttachmentCollection("Projects", "42");
// Do something with the attachments
}
正如您所看到的,我尝试将ClientCredential
设置为当前用户的凭据,但似乎并未发送用户名。我的SharePoint站点配置了https和Windows身份验证。下面是我的简单配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpsBinding>
<binding name="ListsSoap">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Ntlm"
proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpsBinding>
</bindings>
<client>
<endpoint address="https://intranet.test.com/_vti_bin/Lists.asmx"
binding="basicHttpsBinding" bindingConfiguration="ListsSoap"
contract="ListServiceProxy.ListsSoap" name="ListsSoap" />
</client>
</system.serviceModel>
</configuration>
我已尝试clientCredentialType="NtlM"
和clientCredentialType="Windows"
,但我得到的结果相同。我的配置文件或我需要在client
上设置的变量有问题吗?