匿名身份验证发布站点的SharePoint 2010 WCF RESTful身份验证问题

时间:2011-11-16 20:11:38

标签: wcf sharepoint-2010 restful-authentication

我有一个启用了允许匿名访问的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不在同一服务器上。

1 个答案:

答案 0 :(得分:0)

您应该创建如下所述的绑定。

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); 
相关问题