【发布时间】:2015-10-09 11:30:38
【问题描述】:
我有这个 WCF。当我像 http://localhost:8733/doc/run/Test.doc 这样从 Chrome 浏览器调用它时,wcf 服务返回:
Tect.doc Succeed
但是 Word 的窗口没有出现。我应该更改哪些代码才能打开 Word 的窗口?
namespace WordDavService
{
[ServiceContract]
public interface IWcfDocOpen
{
[WebGet(UriTemplate = "/run/{Path}", ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
string Run(string Path);
}
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
public class DocOpenWcfService : IWcfDocOpen
{
//public static void Main()
public string Run(string Path)
{
Task<string> thread = Task<string>.Factory.StartNew(() =>
{ return DocOpenWcfService.OpenWord(Path); });
Task.WaitAll(thread);
return Path+thread.Result;
}
protected static string OpenWord(string Path)
{
Word._Application application = null; ;
Word._Document document = null; ;
Object _Path = Path;
try
{
application = new Word.Application();
if (!string.IsNullOrEmpty(_Path.ToString()))
document = application.Documents.Open(ref _Path);
application.Visible = true;
}
catch (Exception error)
{
try
{
document.Close();
}
catch { }
try
{
application.Quit();
}
catch { }
document = null;
application = null;
return error.Message+"innerExeption: "+error.InnerException.Message;
}
return "Succeed";
}
}
}
【问题讨论】:
-
为什么要在服务器上打开交互式桌面应用程序?
-
我有指向 WebDav .docx 文档的链接,我想直接在 Word 中打开此文档。这不是服务器,它只是托管在客户端机器上的 Windows 服务。
-
所以你的意思是这个词没有在调用机器上打开,或者那个词没有在运行windows服务的机器上打开?
-
这是同一台机器。在客户端机器上使用 wcf 托管 Windows 服务。当有人像localhost:8733/doc/run/Test.doc 这样调用这个 wcf 时,它应该在本地启动 Word,并使用一个文件名作为 Url 中的参数传递