0

on SharePoint 2019 + May 2022 CU (16.0.10386.20011) we have a C# solution containing webservices that we call from SPFx solutions. This worked fine until this week when we got issue report that we narrowed down to the webservice instantiation failure on SPContext.Current.Web.CurrentUser being null.

We excluded the SPFx frontend as the failure happens also when directly calling the endpoint from browser (e.g. https://Server/_vti_bin/LettersService.svc/Test ) without SharePoint UI in the action.

It's happening only for some users, one user had the issue then in few hours it was gone. It is happening only in our production environment, we could not reproduce it yet in DEV / integration (June 22 CU) / testing (May 22 CU) environments. It is happening on both our webservers, we tried to stop one & try just the other.

Users with the issue already had properly populated SPUser object (ID, LoginName...) on the site, we also tried to ensure the user on the site just in case - no change.

I also tried to add the user directly to a SP group on the site that is calling this webservice - no change.

There is a loadbalancer before the WFEs.

Does anyone have an idea what could be the issue & how to solve it?

class ServiceBase where the context is processed:

namespace SC.IM.WebService.Code
{
    public abstract class ServiceBase
    {
        protected ServiceBase()
        {
            Logger.Instance.LogDebug("ctor ServiceBase");

            if (SPContext.Current == null) return;

            var currentUser = SPContext.Current?.Web?.CurrentUser?.LoginName;
            if (string.IsNullOrEmpty(currentUser)) // here it's null in the issue
            {
                if (SPContext.Current?.Web?.CurrentUser != null)
                {
                    Logger.Instance.LogInfo($"User {SPContext.Current?.Web?.CurrentUser.ID} has no LoginName");

                }
                throw new ArgumentException("No SharePoint context found");
            }

and then the webservices like this

interface with endpoints definition:

namespace SC.IM.WebService.ISAPI.Interfaces
{
    [ServiceContract]
    interface ILettersService
    {
        [OperationContract]
        [WebGet(UriTemplate = "test", ResponseFormat = WebMessageFormat.Json)]
        string Test();
    }
}

class with endpoints implementation, inheriting ServiceBase

namespace SC.IM.WebService.ISAPI
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class LettersService : ServiceBase, ILettersService
    {
        public string Test()
        {
            return "Letters Service Test successful";
        }
    }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.