0

.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 文書には 2 つのブックマークがあり、これらのブックマークを上記のコード内に入力します。

私の開発ボックスでは、すべて正常に動作します。ドキュメントは 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 がインストールされています。

4

1 に答える 1

0

これは、Microsoft Office オートメーションをサーバー側で無人で使用することに固有の安定性の問題だと思います。詳細については、こちらを参照してください。

于 2011-04-04T09:43:07.503 に答える