Click here to Skip to main content
14,242,790 members
Rate this:
Please Sign up or sign in to vote.
See more:
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.


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
Posted
Updated 9-Jul-19 3:29am
Comments
Garth J Lancaster 22-Apr-16 7:53am
   
what profile is the service installed under ? you might need to look at user impersonation http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User to force your code to run as a user or, create a normal user and instruct your service to run as that user
Richard Deeming 22-Apr-16 8:00am
   
Considerations for server-side Automation of Office[^]:
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."

What you're trying to do is not supported.
Philippe Mori 22-Apr-16 12:30pm
   
Don't use Office from a service. Office is not designed for that and this is well known.
Rate this:
Please Sign up or sign in to vote.

Solution 1

I guess that using Outlook from a service won't work. See also this thread: Windows service and outlook integartion[^]:
Quote:
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.

If you still want to try it, this Excel related Blog post might help with identifying some prerequisites:
Running excel from a windows service | Bharath's Tech Blog[^].
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

make sure you have only one instance of outlook opened
   
Comments
Dave Kreskowiak 9-Jul-19 12:21pm
   
You didn't read the 1st solution, did you?

You're answer is meaningless and has nothing to do with the problem described 3 years ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100