Sharepoint 2013 Server running on Win2008 R2
Visual Studio 2012
Have created a Windows c# Library (call it 'LibDec') including the code shown below, the purpose of which is to declare a record
Tested the code using a c# console application within the same VS solution; works perfectly and as expected.
Created a new WCF Service project (call it 'WCFS') and in WCFS referenced compiled version of LibDec library
Configured VS to use the 64-bit edition of IIS Express to debug and test WCFS
Created another separate console solution to test WCFS. Configured basicHttpBinding. Tested. All of this works perfectly and as expected:
Console test app calls WCFS > WCFS References 'LibDec' > 'LibDec' declares a record in Sharepoint
All good up to this point
Next, deploy the WCF service to IIS 7.5 to test and debug against the 'production' deployment scenario. Configured the IIS 7.5 site to use its own application pool running under the Sharepoint Site account, call it SPSetup.
SPSetup has full rights to the Sharepoint Site
Configured bindings to use Impersonation to ensure that the WCF service runs under the Security context of the Windows account that has Full Sharepoint rights
My code now generating this ACCESS DENIED exception, which I cannot resolve.
Have added code to the catch block to check that the code is executing under the context of the account I expect, and it is.
What am I doing wrong?
/>
Qualifiers="0">0</EventID>
Security Principal is xxx\SPSetup. The Sharepoint web user is
xxx\SPSetup. System.UnauthorizedAccessException: Access is denied.
(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at
Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(Exception ex) at
Microsoft.SharePoint.Library.SPRequest.GetListsWithCallback(String bstrUrl, Guid
foreignWebId, String bstrListInternalName, Int32 dwBaseType, Int32
dwBaseTypeAlt, Int32 dwServerTemplate, UInt32 dwGetListFlags, UInt32
dwListFilterFlags, Boolean bPrefetchMetaData, Boolean bSecurityTrimmed, Boolean
bGetSecurityData, Boolean bPrefetchRelatedFields, ISP2DSafeArrayWriter
p2DWriter, Int32& plRecycleBinCount) at
Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId, String
strListName) at Microsoft.SharePoint.SPListCollection.GetListByName(String
strListName, Boolean bThrowException) at
arbsp15Client.DeclareRecordClass.<>c__DisplayClass2.<DeclareRecord>b__0()
in c:\Users\spsetup\Documents\Visual Studio
2012\Projects\arbsp15Client\arbsp15Client\DeclareRecord.cs:line 37 at
Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.<RunWithElevatedPrivileges>b__3()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated
secureCode) at
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback
secureCode, Object param) at
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated
secureCode) at arbsp15Client.DeclareRecordClass.DeclareRecord(String siteUrl,
String listTitle, Int32 listItemID, String eventLogSource) in
c:\Users\spsetup\Documents\Visual Studio
2012\Projects\zzz\zzz\DeclareRecord.cs:line 32</Data>
public static int DeclareRecord(String siteUrl,
String listTitle,
int listItemID,
String eventLogSource)
{
int r = 0;
SPWeb oWeb = null;
SPList oList = null;
SPSite oSite = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
oSite = new SPSite(siteUrl);
oWeb = oSite.OpenWeb();
});
oWeb.Lists.ListsForCurrentUser = true;
oList = oWeb.Lists[listTitle];
SPListItem oListItem = oList.Items.GetItemById(listItemID);
if (!Records.IsRecord(oListItem))
{
Records.DeclareItemAsRecord(oListItem);
r++;
}
}
catch (Exception e)
{
String wLoginName = ((oWeb == null) ? String.Empty : oWeb.CurrentUser.LoginName);
System.Diagnostics.EventLog.WriteEntry(eventLogSource, String.Format("An exception was thrown trying to declare a record. The Windows Security Principal is {1}. The Sharepoint web user is {2}. {0}",
new Object[] { e.ToString(),
System.Security.Principal.WindowsPrincipal.Current.Identity.Name.ToString(),
wLoginName}));
r = -1;
}
return (r);
}