开发者

Sharepoint 2010 Client Object Model Remote Access via HTTPS

开发者 https://www.devze.com 2023-01-05 12:25 出处:网络
I was encouraged to learn that the Sharepoint 2010 Client Object Model essentially wraps remote calls to the server.So, I copied the Microsoft.Sharepoint.Client.Silverlight.dll and Microsoft.Sharepoin

I was encouraged to learn that the Sharepoint 2010 Client Object Model essentially wraps remote calls to the server. So, I copied the Microsoft.Sharepoint.Client.Silverlight.dll and Microsoft.Sharepoint.Client.Silverlight.Runtime.dll from my Sharepoint 2010 server to my development machine (without Sharepoint). I assumed the Silverlight code I tested on the Sharepoint 2010 server would also work on my development machine. Naturally, I don't use the "ApplicationContext.Current.Url" because I am not executing in Sharepoint, so I manually add sharepoint server name as follows (kept anonymous for the post):

        //ClientContext context = new ClientContext(ApplicationContext.Current.Url);
        ClientContext context = new ClientContext("https://[servername]");
        _web = context.Web;
        context.Load(_web);
        context.Load(_web.Lists);
        context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler  (OnRequestSucceeded), new ClientRequestFailedEventHandler(OnRequestFailed));

When I execute the code, I am prompted by a Windows Authentication window (Sharepoint is configured to use Windows Authentication), I add my domain/user and password. However, I am getting the following error:

Note: I was able to get Sharepoint 2010 web services working given a similar error by changing the binding security mode="Transport" and including a clientAccessPolicy.xml file on the Sharepoint root website. Do I need to configure another Sharepoint directory for thje Client Object Model end开发者_高级运维point?

  • Exception {System.Security.SecurityException ---> System.Security.SecurityException: Security error. at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.b__4(Object sendState) at System.Net.Browser.AsyncHelper.<>c__DisplayClass2.b__0(Object sendState) --- End of inner exception stack trace --- at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state) at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryGetResponseAsyncCallback(IAsyncResult asyncResult)} System.Exception {System.Security.SecurityException}


Please look in to the below blog post, you need to add clientaccesspolicy.xml file in your sharepoint website root folder.

http://vangalvenkat.blogspot.com/2011/08/sharepoint-2010-getting-list-item.html


Aha, I found it. You can set the security on the client context to use the default windows authentication like so:

using (Microsoft.Sharepoint.Client.ClientContext ctx = new Microsoft.Sharepoint.Client.ClientContext("http://sharepointserver")){

ctx.AuthenticationMode = Microsoft.Sharepoint.Client.ClientAuthenticationMode.Default

} 

This should also prevent any windows authentication pop-ups

0

精彩评论

暂无评论...
验证码 换一张
取 消