Word automation RRS feed

  • Question

  • Hello

    I have a web service that has to produce a word document in doc format. That document is to be used as an input of a legacy pdf converter, so I have not the opportunity to chose another format, like docx. I'm stucked with word automation though. I know that MS do not recommend office automation in servers but I will have to go with it... have no choice.

    I've written my app code and in development environment, when launching Visual Studio internal web server, all goes well and my document is produced.

    My problem arises when i try to publish the web service site to IIS, even in the same machine where I do all the development. Then, when invoking the service, word automation reports the following error, after running the Documents.Add command of oWord object. It never reaches the third debug statement, and signals the following error: 

    System.Runtime.InteropServices.COMException (0x800706BE): The remote procedure call failed

    I've add the proper permissions to DCOM word module.

    My relevant code is the following:

    // ***
    // process document
    object oMissing = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Word._Document oDoc;
                                        oWord = new Microsoft.Office.Interop.Word.Application();
    // ***
    // open template
    object oTemplate = ConfigurationManager.AppSettings["template"];
    oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
    // ***

    The line reporting the error is 

    oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

    Can you help me in this?

    It's been challenging... it works well when in development environment, and crashes when in IIS on the same machine.



    Wednesday, October 24, 2012 2:38 PM