在测试服务器上自动运行Word时出错

时间:2010-09-20 12:35:09

标签: asp.net ms-word word-automation

我正在尝试从.Net Web应用程序打开Word文档。代码(简而言之)包含......

using Word = Microsoft.Office.Interop.Word;
using System.Reflection;

并且,实际创建文档的代码包括:

object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; // \endofdoc is a predefined bookmark 
object oTemplate = WebConfigurationManager.AppSettings["GuidelineRepsTemplate"]; //this points to a .doc I am using as a template

//Start Word and create a new document.
    Word._Application oWord;
    Word._Document oDoc;
    oWord = new Word.Application();
    oWord.Visible = true;
    oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);

    object oBookMark = "Representative";
    oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = lblRecipient.Text;

    object oBookMark1 = "Guidelines";
    oDoc.Bookmarks.get_Item(ref oBookMark1).Range.Text = Guidelines.ToString();

object fileName = WebConfigurationManager.AppSettings["GuidelineRepsPath"] + ContactID.ToString() + "\\" + fileString2 + ".doc";
        object FileFormat = Word.WdSaveFormat.wdFormatDocument;
        oDoc.SaveAs(ref fileName, ref FileFormat, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

我用作模板的Word文档中有两个书签,我在上面的代码中填充了这些书签。

在我的开发盒上一切正常。文档在Word中打开,用户可以根据需要进行更改,并将其保存在我为其创建的目录中(目录代码未在上面显示)。

当我发布到测试服务器时 - 每次运行它时都会出现此错误:

The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER)) 

堆栈跟踪无法让人注意到错误 - 例如:

[COMException (0x8001010a): The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))]
Microsoft.Office.Interop.Word.DocumentClass.get_Bookmarks() +0
SendConfirmEmailReps.CreateDocs(Int32 ContactID, Int32 OrganisationID) +942
SendConfirmEmailReps.Page_Load(Object sender, EventArgs e) +317
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

表明书签有问题。所以我引用了书签,开始使用一个名为Hello.doc的文件作为我的模板。没有书签 - 只有'你好'这个词。

这也失败了 - 但是StackTrace表明是在调用SaveAs的时候。

所以,问题是......为什么它可以在我的开发盒上工作,但不能在服务器上工作。服务器上安装了Word。

1 个答案:

答案 0 :(得分:0)

我认为这是Microsoft Office自动化服务器端无人值守使用中固有的稳定性问题。它更详细地描述了here