Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “错误”;未提供用户名。在ClientCredentials中指定用户名;传递CredentialCache.DefaultNetworkCredentials时_C#_Wcf_Sharepoint 2010 - Fatal编程技术网

C# “错误”;未提供用户名。在ClientCredentials中指定用户名;传递CredentialCache.DefaultNetworkCredentials时

C# “错误”;未提供用户名。在ClientCredentials中指定用户名;传递CredentialCache.DefaultNetworkCredentials时,c#,wcf,sharepoint-2010,C#,Wcf,Sharepoint 2010,我正在编写一个简单的C#控制台应用程序,它将调用SharePoint网站上的“Lists.asmx”web服务以下拉附件。我已经添加了服务引用并尝试运行它,但失败了,出现了错误 未提供用户名。在ClientCredentials中指定用户名 当它尝试对GetAttachmentCollection进行服务方法调用时。代码如下: static void Main(string[] args) { ListsSoapClient client = new ListsSoapClient();

我正在编写一个简单的C#控制台应用程序,它将调用SharePoint网站上的“Lists.asmx”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”
,但得到了相同的结果。我的配置文件或需要在
客户机上设置的变量是否有问题

把安全模式改成。你有什么特别的理由要用吗TransportWithMessageCredential@yyou谢谢,我把它改为“传输”,它不再提示我输入用户名。我没有任何特别的理由使用“TransportWithMessageCredential”,但我不确定使用哪一个。我想我应该仔细阅读这本书。把你的评论变成答案,我一定会接受的。