Unable to connect to the remote server.Azure Finction.CSOM.Share point

Nerobov Andrey 96 Reputation points
2020-10-19T12:58:12.537+00:00

I have Azure Function and share point online,when I try to get item by id in azure fucntion, i get exception.I always use the service account in the code.What am I doing wrong? thanks

Unable to connect to the remote server Stack: at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.GetIdcrlHeader(Uri url, Boolean alwaysThrowOnFailure, EventHandler1 executingWebRequest) at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.GetAuthenticationCookie(Uri url, String username, SecureString password, Boolean alwaysThrowOnFailure, EventHandler1 executingWebRequest) at Microsoft.SharePoint.Client.SharePointOnlineCredentials.GetAuthenticationCookie(Uri url, Boolean refresh, Boolean alwaysThrowOnFailure) at Microsoft.SharePoint.Client.ClientRuntimeContext.SetupRequestCredential(ClientRuntimeContext context, HttpWebRequest request) at Microsoft.SharePoint.Client.SPWebRequestExecutor.GetRequestStream() at Microsoft.SharePoint.Client.ClientContext.GetWebRequestExecutor() at Microsoft.SharePoint.Client.ClientContext.<GetFormDigestInfoPrivateAsync>d__b.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.<EnsureFormDigestAsync>d__8.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContext.<ExecuteQueryAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay, String userAgent) at DD_ProjectApproval_Helper.ListCommonActions.GetItembyID(String listName, Int32 id, ClientContext context) in D:\O365_Development\SP.ProjectApproval\DD_ProjectApproval_Helper\ListCommonActions.cs:line 91 at DD.ProjectApproval.DataLayer.ProjectListActions.GetProjectByid(Int32 prjid, ClientContext context) in D:\O365_Development\SP.ProjectApproval\DD.ProjectApproval.DataLayer\ProjectListActions.cs:line 42 at FunctionAppV1.StartApprovalFunction.<Run>d__0.MoveNext()

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,093 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,814 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Baker Kong-MSFT 3,801 Reputation points
    2020-10-20T07:05:47.243+00:00

    Hi @Nerobov Andrey ,

    How do you set your Azure function? By default the runtime stack is .NetCore, while Microsoft.SharePoint.Client.SharePointOnlineCredentials is in CSOM for .Net Framework. Have you set up .net freamwork environment?

    33534-image.png

    I tested below demo in my Azure function and it could connect to SPO:

    Besides, CSOM for .NET Standard has released, it could be used in .net core but it does not support SharePointOnlineCredentials

    Best Regards,
    Baker Kong


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Nerobov Andrey 96 Reputation points
    2020-10-30T09:36:56.24+00:00

    @Baker Kong-MSFT all right, this problem was because my azure function used all free sockets ( more than 300 000)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.