SharePoint 2010 WCF RESTful身份验证问题与匿名身份验证发布网站

SharePoint 2010 WCF RESTful身份验证问题与匿名身份验证发布网站,wcf,sharepoint-2010,restful-authentication,Wcf,Sharepoint 2010,Restful Authentication,我有一个打开了允许匿名访问的SharePoint 2010发布网站,我在使用WCF RESTful数据访问时遇到一些问题 首先,当我尝试在Visual Studio 2010中创建一个数据源来listdata.svc时,它会失败,除非我进入IIS并在_vti_bin上禁用匿名身份验证。如果我在_vti_bin上禁用匿名身份验证,我就能够无误地添加数据源 第二,如果我在_vti_bin上禁用了匿名身份验证,并尝试与SharePoint Designer连接,则在提示输入用户名/密码后会出现错误 第

我有一个打开了允许匿名访问的SharePoint 2010发布网站,我在使用WCF RESTful数据访问时遇到一些问题

首先,当我尝试在Visual Studio 2010中创建一个数据源来listdata.svc时,它会失败,除非我进入IIS并在_vti_bin上禁用匿名身份验证。如果我在_vti_bin上禁用匿名身份验证,我就能够无误地添加数据源

第二,如果我在_vti_bin上禁用了匿名身份验证,并尝试与SharePoint Designer连接,则在提示输入用户名/密码后会出现错误

第三,如果我在_vti_bin上允许匿名身份验证,并尝试运行我的WCF RESTful代码,那么传入的凭据似乎没有被使用。参见代码

 static void Main(string[] args)
    {  
        MySite.MySiteDataContext dc = new MySite.MySiteDataContext(new Uri("http://mysite/_vti_bin/ListData.svc/"));

        dc.Credentials = new NetworkCredential("user", "password", "domain");


        var q = from m in dc.Products
                select m;


        foreach (var i in q)
        { 

           //never gets in here when Anonymous Authentication is allowed on the _vti_bin       
           //when Anonymous Authentication is disabled on _vti_bin this code runs without issue. 

        }
    }
所以。。。谁能告诉我我做错了什么,或者是否有解决这个问题的办法

环境:

SharePoint 2010 启用匿名访问的发布网站
在控制台应用程序中运行的代码与SharePoint server不在同一服务器上。

您应该创建一个绑定,如下所述

BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.MaxReceivedMessageSize = Int64.MaxValue; 
basicHttpBinding.TransferMode = TransferMode.StreamedResponse; 
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 
EndpointAddress endpoint = new EndpointAddress("yoururl"); 
basicHttpBinding.CloseTimeout = new TimeSpan(0, 10, 0, 0); 
basicHttpBinding.OpenTimeout = new TimeSpan(0, 10, 0, 0); 
basicHttpBinding.ReceiveTimeout = new TimeSpan(0, 10,## Heading ## 0, 0);
basicHttpBinding.SendTimeout = new TimeSpan(0, 10, 0, 0); 
DataService.ServiceClient obj = new DataService.ServiceClient(basicHttpBinding, endpoint);