Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Authenticate to a SharePoint REST Service using the Server Object Model

$
0
0

Hi,

Currently, we're developing a solution for a on-premise SharePoint 2013 Site (this site is configured with Claims Based Authentication). This solution calls several REST Services, some of which are SharePoint REST Services. After having Googled some options and having tried some of them, I can't get it to work as I want to.

The problem seems to be with the authentication. When I set the HttpWebRequest credentials to

request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

I get an error:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.HttpWebRequest.MakeMemoryStream(Stream stream) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse() at CircleSoftware.SharePoint.StudieBegeleiding.DataWebPart.FillDataTable(String user)

If I use this in a SharePoint 2013 site that uses Windows Authentication, the error does not occur. Also (back in the Claim Based SharePoint site), when I explicitly create network credentials using a username and password, the error does not occur:

request.Credentials = new NetworkCredential("some username", " some password", " some domain");

I've tried several options from Google, but all seem to come down to this. The preferred solution is NOT to provide username and password (with domain), but to use user information present in the code (SPUser, context credential info, etc).

Can anyone help me with this? And if you don't know the solution to this, please let me know what should be the right way to go.

Thanks in advance for all you replies!

Cheers,

Ruud.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>