2013-01-10 2 views
0

내 WebService는 ms 단어 COM을 사용하여 2 개의 .doc 파일을 비교합니다. 결과 파일이 1MB 이상이 될 때까지 끊깁니다. (작은 파일의 경우 모든 것이 정상입니다). & IIS에 WebService를 게시하면 문제가 발생합니다. (호스트 아래에 승 serv 2008 x 64, IIS - 7) 그래서, COM COM 참조로 서비스에 추가됩니다. 거기에 ms word 2010 x64를 설치해야했습니다. 그렇지 않으면 서비스가 null ref 예외를 throw합니다.웹 서비스 MS Word 비교 자동화 원인 동결

내 로컬 comp에서 (VS 디버그 모드에서) win 7 및 office 2010 32 비트에서는 모든 것이 정상입니다.

세부 사항 : I는 웹 서비스 호출 JS를 사용하고 있습니다 :

function post_to_url() { 
    var path = "http://localhost:32496/Service1.asmx/runCompareService"; 
    var params = {'mAuthToken':'xU/fnlKCe85R25I8IIRHIQCmPc7rcajYVHLQ3JChv8w=','documentId':'1441378','origVerNum':'1','revisedVerNum':'2'}; 
    var method = "post"; 
    var form = document.createElement("form"); 
    form.setAttribute("method", method); 
    form.setAttribute("action", path); 

     for(var key in params) { 
      if(params.hasOwnProperty(key)) { 
      var hiddenField = document.createElement("input"); 
      hiddenField.setAttribute("type", "hidden"); 
      hiddenField.setAttribute("name", key); 
      hiddenField.setAttribute("value", params[key]); 
      form.appendChild(hiddenField); 
      } 
     } 

     document.body.appendChild(form); 
     form.submit(); 
    } 

C#을 방법 비교 :

public void doCompare(String file1path, String file2path, String file3path) 
    { 
     Microsoft.Office.Interop.Word.Application wordApp = null; 
     Microsoft.Office.Interop.Word.Document doc1 = null; 
     Microsoft.Office.Interop.Word.Document doc2 = null; 
     Microsoft.Office.Interop.Word.Document doc = null; 

     object wordTrue = (object)true; 
     object wordFalse = (object)false; 
     object missing = Type.Missing; 

     object fileToOpen = @file1path; 
     object fileToOpen1 = @file2path; 
     object fileToSave = @file3path; 

     try 
     { 
      wordApp = new Microsoft.Office.Interop.Word.Application(); 
      wordApp.Visible = false; 
      wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone; 
      try 
      { 
       doc1 = wordApp.Documents.Open(ref fileToOpen, ref missing, ref wordFalse, ref wordFalse, ref missing, 
       ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref wordTrue, ref missing, 
       ref missing, ref missing, ref missing); 
      } 
      catch (Exception e) 
      { 
       throw new Exception("Failed to open approved file" + e.ToString()); 
      } 
      try 
      { 
       doc2 = wordApp.Documents.Open(ref fileToOpen1, ref missing, ref wordFalse, ref wordFalse, ref missing, 
       ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
       ref missing, ref missing, ref missing); 
      } 
      catch (Exception e) 
      { 
       throw new Exception("Failed to open revised file" + e.ToString()); 
      } 
      if ((doc1 != null) && (doc2 != null)) 
      { 
       try 
       { 
        doc = wordApp.CompareDocuments(doc1, doc2, WdCompareDestination.wdCompareDestinationOriginal, WdGranularity.wdGranularityWordLevel, 
        true, true, true, true, true, true, true, true, true, true, "", false); 
        doc.SaveAs2(fileToSave); 
        ((_Document)doc).Close(); 
       } 
       catch (Exception e) 
       { 
        throw new Exception("Failed to save compare result file" + e.ToString()); 
       } 
      } 
     } 
     catch (Exception e) 
     { 
      throw new Exception("Failed to open MS Word Application" + e.ToString()); 
     } 
     finally 
     { 
      ((_Application)wordApp).Quit(); 
     } 
    } 

응답으로 변경이 :

private void DownloadToBrowser(String filePath) 
    { 
     FileInfo file = new FileInfo(filePath); 
     byte[] fileBytes = ReadFile(filePath); 

     Context.Response.Clear(); 
     Context.Response.ClearHeaders(); 
     Context.Response.ClearContent(); 
     Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); 
     Context.Response.AddHeader("Content-Length", file.Length.ToString()); 
     Context.Response.AddHeader("Connection", "close"); 
     Context.Response.ContentType = "application/msword"; 
     Context.Response.ContentEncoding = Encoding.UTF8; 
     Context.Response.OutputStream.Write(fileBytes, 0, fileBytes.Length); 
     Context.Response.Flush(); 
     Context.ApplicationInstance.CompleteRequest(); 
    } 

이 서비스 같이이다 COM 비교 작업에 응답하지 않음

try 
{ 
    doc = wordApp.CompareDocuments(doc1, doc2, WdCompareDestination.wdCompareDestinationOriginal, WdGranularity.wdGranularityWordLevel, 
        true, true, true, true, true, true, true, true, true, true, "", false); 
     doc.SaveAs2(fileToSave); 
     ((_Document)doc).Close(); 
} 
catch (Exception e) 
{ 
     throw new Exception("Failed to save compare result file" + e.ToString()); 
} 

누군가 도움을 줄 수 있습니까?

+0

가능한 중복 [오피스를 사용하여 asp.net 웹 서비스 2010 COM (http://stackoverflow.com/questions/7382704/asp-net-web -service-using-office-2010-com) –

답변

1

Office 자동화는 데스크톱 프로그램 (Word, Excel 등)을 자동화하기 위해 개발되었습니다. 데스크톱 환경에서 작동한다는 많은 가정을합니다. 예를 들어, 다중 스레드 프로세스에서 실행될 때 문제가 발생할 수 있습니다.

전혀 작동하지 않습니다. 운이 좋으면 즉시 실패하고 다른 해결책을 찾을 수 있습니다. 운이 좋으면 운이 좋지 않을 것이며, 생산에 들어갈 것이고, 그것에 의지 할 것이고, 다음 문제를 해결하기가 어렵고 해결이 불가능한 심각한 문제가 발생하기 시작할 것입니다.

참조하지 않는다 asp.net web service using office 2010 COM