在net 4.0中创建的Windows服务无法打开Outlook实例 [英] Windows service created in net 4.0 fails to open outlook instance
问题描述
I have created windows service in .Net 4.0. Service is written to open outlook client, read emails from Inbox folder, downloads attachments.The code written is correct, since I have run & tested it in windows application project.
But when I install the web service using "installutil" and run it, the service throws following error on following line of code:
private static Microsoft.Office.Interop.Outlook.Application app = null;
private static Microsoft.Office.Interop.Outlook._NameSpace ns = null;
private static Microsoft.Office.Interop.Outlook.Attachments attachments = null;
Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
ns = myApp.GetNamespace("MAPI");
Error:
Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80010001 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))
FYI, the service is fails to run on my local machine.
I feel that service might require some permission, if so please let me know how to assign permissions to windows service.
Please Help.
我尝试过:
private static Microsoft.Office.Interop.Outlook.Application app = null;
private static Microsoft.Office.Interop.Outlook._NameSpace ns = null;
private static Microsoft.Office.Interop.Outlook.Attachments attachments = null;
Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace(MAPI);
ns = myApp.GetNamespace
What I have tried:
private static Microsoft.Office.Interop.Outlook.Application app = null;
private static Microsoft.Office.Interop.Outlook._NameSpace ns = null;
private static Microsoft.Office.Interop.Outlook.Attachments attachments = null;
Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
ns = myApp.GetNamespace
推荐答案
我想从服务中使用Outlook赢了不行。另见这个主题: Windows服务和Outlook整合 [ ^ ]:
I guess that using Outlook from a service won't work. See also this thread: Windows service and outlook integartion[^]:
就使用服务中的Outlook而言,Outlook将抛出无法禁用的模式对话框/错误/警告。这不适合在服务中使用。 MS也不支持在服务中使用Outlook。
As far as using Outlook from a service, Outlook will throw up modal dialogs/errors/warnings that cannot be disabled. That's not suitable for use in a service. MS also does not support using Outlook in a service.
如果您仍想尝试,这篇与Excel相关的博客文章可能有助于确定一些先决条件:
从Windows服务运行excel | Bharath' s Tech Blog [ ^ ]。
这篇关于在net 4.0中创建的Windows服务无法打开Outlook实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!