code:
string siteURL = "http://win-mkd3blj5kda/sites/test";
SPSite spSite = new SPSite(siteURL);
SPWeb web = spSite.RootWeb;
SyncConverter syncConv = new SyncConverter("Word Automation Services");
syncConv.UserToken = spSite.UserToken;
syncConv.Settings.OutputFormat = SaveFormat.PDF;
syncConv.Settings.UpdateFields = true;
syncConv.Settings.OutputSaveBehavior = SaveBehavior.AlwaysOverwrite;
FileStream aFile = File.OpenRead("c:\\test.docx");
Stream stream = new MemoryStream();
ConversionItemInfo convInfo = syncConv.Convert(aFile, stream);
error:
Microsoft.SharePoint.SPException was unhandledHResult=-2146232832
Message=The service application required to complete this request is not currently available. Try this operation again later. If the problem persists, contact your administrator.
Source=Microsoft.Office.Word.Server
ErrorCode=-2146232832
StackTrace:
在 Microsoft.Office.ConversionServices.Service.ConversionServiceApplicationProxy.ExecuteOnChannel(Uri endpointAddress, Action`1 action)
在 Microsoft.Office.ConversionServices.Service.ConversionServiceApplicationProxy.AddSyncStreamJob(Ucid ucid, Nullable`1 subscriptionId, ConversionJobSettings settings, List`1 inputStream, Uri& endpointAddress)
在 Microsoft.Office.ConversionServices.Conversions.SyncConverter.Convert(List`1 inputStream, Byte[]& outputStreamInBytes)
在 Microsoft.Office.Word.Server.Conversions.SyncConverter.Convert(List`1 inputStream, Byte[]& outputStreamInBytes)
在 Microsoft.Office.Word.Server.Conversions.SyncConverter.Convert(Stream inputStream, Stream outputStream)
在 PDFLog.Program.ConvertSync() 位置 C:\Users\yanguantao\Desktop\PDFLog\PDFLog\Program.cs:行号 30
在 PDFLog.Program.Main(String[] args) 位置 C:\Users\yanguantao\Desktop\PDFLog\PDFLog\Program.cs:行号 38
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: