The following code successfully adds claimed based user when run as console application
SPSite site = new SPSite(siteUrl);
var spWeb1 = site.RootWeb;
spWeb1.AllowUnsafeUpdates = true;
spUser = spWeb1.EnsureUser(loginName);
spWeb1.Update();
spWeb1.AllowUnsafeUpdates = false;
But we have WCF service where we implemented these code to add user and and hosted as Windows Service. When a client application invokes this methods, it fails to add user with the following exception:
SPException: The specified user i:0#.f|aspnetsqlmembershipprovider|cu09 could not be found
at Microsoft.SharePoint.SPWeb.EnsureUser(String logonName)
I have also tried to run the codes in elevated mode but it also fails.
Can you shed some light why the above codes work in console application but not in WCF Service?
Thanks.