asp.net servicio web usando Office 2010 COM
Estoy escribiendo un servicio web y me gustaría cambiar el .docx o .doc a .xps. Estoy usando office com para ayudarme a guardar como formato .xps de la siguiente manera:
[WebMethod]
public string GetDocPreviewUrl(string m_userName, string m_orgFileName)
{
string m_returnUrl = "";
string m_orgFilePath = _currentDirectory + "\\" + m_userName + "\\" + m_orgFileName;
if (File.Exists(m_orgFilePath))
{
string m_xpsFilePath = _currentDirectory + "\\" + m_userName + "\\" +
Path.GetFileNameWithoutExtension(m_orgFileName) + ".xps";
OfficeToXpsConversionResult m_converstionResult = OfficeToXps.ConvertToXps(m_orgFilePath, ref m_xpsFilePath);
m_returnUrl = _baseUrl + m_userName + "/"+ Path.GetFileName(m_xpsFilePath);
}
return m_returnUrl;
}
private static OfficeToXpsConversionResult ConvertFromWord(string sourceFilePath, ref string resultFilePath)
{
object pSourceDocPath = sourceFilePath;
string pExportFilePath = string.IsNullOrWhiteSpace(resultFilePath) ? GetTempXpsFilePath() : resultFilePath;
Word.Application() wordApplication = new Word.Application();
//wordDocument = wordApplication.Documents.Open(ref pSourceDocPath);
dynamic wordDocument = wordApplication.Documents.Add(pSourceDocPath);
//return new OfficeToXpsConversionResult(ConversionResult.ErrorUnableToOpenOfficeFile, exc.Message, exc);
if (wordDocument != null)
{
wordDocument.SaveAs(pExportFilePath, WdSaveFormat.wdFormatXPS);
}
resultFilePath = pExportFilePath;
return new OfficeToXpsConversionResult(ConversionResult.OK, pExportFilePath);
}
Sin embargo, recibí una excepción cuando trato de llamar por el método web:
System.Runtime.InteropServices.COMException: Word 發生 問題。 en System.Dynamic.ComRuntimeHelpers.CheckThrowException (Int32 hresult, ExcepInfo & exceptInfo, UInt32 argErr, String message) en CallSite.Target (Closure, CallSite, ComObject, Object). Dynamic.UpdateDelegates.UpdateAndExecute2 [T0, T1, TRet] (sitio CallSite, T0 arg0, T1 arg1) en CallSite.Target (Closure, CallSite, Object, Object) en System.Dynamic.UpdateDelegates.UpdateAndExecute2 [T0, T1, TRet] (Sitio de CallSite, T0 arg0, T1 arg1) en DocProcessService.OfficeToXps.ConvertFromWord (String sourceFilePath, String & resultFilePath) en C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeTops 145. .OfficeToXps.ConvertToXps (String sourceFilePath, String & resultFilePath) en C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ OfficeHelper \ OfficeToXps.cs: línea 63 en DocProcessService.DocDownload.GetDinging.GetDoc. gFileName) en C: \ Users \ Icicle \ Documents \ Fotomax WP7 \ DocProcessService \ DocProcessService \ DocDownload.asmx.cs: línea 90
El código de uso de Office para guardar como xps funcionaba bien en mi proyecto WPF. ¿Cómo puedo usarlo en mi servicio web asp.net 4.0? Gracias