First a question, did you create the WCF service using CKSDEV, which creates a SharePoint WCF Service Factory based WCF (cleaner, full SharePoint support, no need for a config file), or a "regular" WCF service deployed to the ISAPI folder?
Also, I do see a few problems:
First, To consume a WCF service running in SP, you always need to set the impersonation level in the consuming code:
var client = new YourServiceClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
Second, elevation only works if you actually create a new context inside it,
SPSecurity.RunWithElevatedPrivileges(delegate{
using (SPSite newspSite = SPContext.Current.Site)
{
// your elevated actions (not actually elevated
}
}); // the current context is disposed!!
does not create an alevated site object, even worse, it disposes the actual current context! Use the following:
SPSecurity.RunWithElevatedPrivileges(delegate{
using (SPSite newspSite = new SPSite(SPContext.Current.Site.Url))
{
// your elevated actions
}
});
Last: Anything running at the farm level being called from a webapp will not work, seeing as even under elevated prviliges the code will run as the web app's apppool, which is not a farm admin (I hope :-D).
Call the service under the Central Admin, which makes it run under that site's app pool (the farm account). This does mean the user running the code needs farm level access, so probably not going to work.
In the past i have circumvented this by assigning an account to a web app's root site collection's secondary site admin. This is a service account (so in AD does not have any logon permissions: logon locally, logon as batch / service etc.)
This user should be made a member of the farm admin group. Then use the following code to get that user and then run code as that user:
SPSecurity.RunWithElevatedPrivileges(delegate{
using (SPSite elevatedSite = new SPSite(SPContext.Current.Site.Url))
{
using (SPSite newspSite = new SPSite(elevatedSite.Url, elevatedSite.SecondaryContact.UserToken))
{
// your elevated actions, running as the secondary admin
}
}
});
P.S. The doc conversion service runs asynchronously, so after firing the job, you don't know when it actually executes, so you can't for instance download the resulting document immediately after.
SPSite newspSite = SPContext.Current.Site
intoSPSite newspSite = new SPSite(SPContext.Current.Site.Id)
? By the way you should NEVER writeusing (SPSite newspSite = SPContext.Current.Site)
as this will dispose a SPSite you're not in control of.using
statement. I am changing my other code accordingly.