Office-Automatisierung (Interop) unter Windows Server 2012

Ich verwende erfolgreich die Office-Automatisierung unter Windows Server 2008 R2 mit Office 2007, um Office-Dokumente in PDF-Dateien zu konvertieren. Der Code ist ziemlich einfach:

public class WordConvert
{
    /// <summary>
    /// Converts a word file to PDF
    /// </summary>
    /// <param name="sourceFilePath">The path of the word file to convert</param>
    /// <param name="targetFilePath">The path of the PDF output file</param>
    public static void ConvertWord(string sourceFilePath, string targetFilePath)
    {
        object objTragetFileName = targetFilePath;
        Word.Application wordDocument = new Word.Application();
        try
        {
            OpenWord(sourceFilePath, wordDocument);
            SaveAsPDF(ref objTragetFileName, wordDocument);
        }
        finally
        {
            CloseWord(wordDocument);
        }
    }

    private static void OpenWord(object sourceFileName, Word.Application wordDocument)
    {
        wordDocument.Documents.Open(ref sourceFileName);
    }

    private static void SaveAsPDF(ref object targetFileName, Word.Application wordDocument)
    {
        object format = Word.WdSaveFormat.wdFormatPDF;
        wordDocument.ActiveDocument.SaveAs(ref targetFileName, ref format);
    }

    private static void CloseWord(Word.Application wordDocument)
    {
        if (wordDocument != null)
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();

            // 2nd time to be safe
            GC.Collect();
            GC.WaitForPendingFinalizers();

            Word.Documents documents = wordDocument.Documents;
            documents.Close();
            Marshal.ReleaseComObject(documents);
            documents = null;


            Word.Application application = wordDocument.Application;
            application.Quit();
            Marshal.ReleaseComObject(application);
            application = null;
        }
    }
}

Das Problem ist, dass dieser Code unter Windows Server 2012 nicht funktioniert. Der Fehler lautet:

System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

Das Ausführen des Codes als interaktiver Benutzer (Konsolenanwendung) funktioniert einwandfrei, schlägt jedoch fehl, wenn er über die IIS-Webanwendung oder den Windows-Dienst ausgeführt wird (auch wenn der Dienst mit dem Desktop interagieren kann). Der Benutzer, der die App ausführt, verfügt über ausreichende Berechtigungen (Administrator), und der Code funktioniert einwandfrei mit Office 2010.

Irgendwelche Ideen?

Antworten auf die Frage(3)

Ihre Antwort auf die Frage