3

I have a Windows Service written in .NET C# which calls a COM component. I also have a .NET Windows Forms test app which I was using to test the COM component. It works fine from the test app. However, when I use the same code in the Windows Service nothing happens. The COM components logs everything to file and the fact the log file doesn't get produced hints that the COM component isn't even being called.

Why does this work from my test app but not within the windows service?

4
  • Please give some detail about the COM component. What is it written in, for instance. Maybe the component assumes it is running in a process that has a message pump. Commented Jun 20, 2011 at 14:19
  • The component is written in ATL with Visual Studio 6. It is an exe component (not dll or service) Commented Jun 20, 2011 at 14:34
  • so, is this the first time you've tried to use the component outside of a desktop application? Never used it in ASP.NET or a web service? That suggests you have a dependency on a message pump or something else that doesn't exist outside of a desktop application. Commented Jun 20, 2011 at 18:26
  • Yes this is the first time I've tried to use outside anything other than a desktop application. I'm thinking there is some sort of permissions problem which I am trying to narrow down. Right now I want to narrow down whether the method gets called at all. Commented Jun 21, 2011 at 8:46

2 Answers 2

4

Service typically run isolated from the desktop, and therefore your call to the COM component is insulated from the UI when called from the service. You may allow a service to "interactWithDesktop" see the section on Using an Interactive Service.

Microsoft (<sarcasm>in their infinite wisdom</sarcasm>) Decided that this capability would be removed from Window vista and recommend separating your application into multiple parts and using other mechanisms to accomplish communication between your UI and your service. Obviously, some (including myself) don't agree, but, it is what it is...

http://msdn.microsoft.com/en-us/library/ms683502.aspx

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/e50d8819-d628-48e2-aa2c-6ac6de8380d9/

Sign up to request clarification or add additional context in comments.

12 Comments

How does that relate to being able to call a COM component from a .NET service?
I suspect that the service IS communicating with COM, but you are not observing that interaction because COM (operating in the service space) can not interact with your desktop (or other user space) to allow you to see that the component is working.
Why is it if I debug the com component, when I call it from the windows forms app written in C# .NET it will break on the breakpoint at the start of the method but when it is called from the windows service it does not break? This is why I don't think it is calling the COM component.
Are you just attempting to run the service from VS or are you attaching to the process? Debugging a service is a little bit different from debugging a Winforms app. (msdn.microsoft.com/en-us/library/7a50syb3%28v=VS.100%29.aspx)
I am not trying to debug the service. I am debugging the com component being called from the windows service. I can debug the windows service just fine by attaching to the running instance of it. But that is not what I am looking to do currently. I can see that the service is attempting to call the COM component but it doesn't call it. The same code works fine from a forms app.
|
1

Are you running your service in the LocalSystem account (the default for Windows Services)? Your COM component may need to access resources available in an account that can run it normally...

Try editing your service and specifying your account on the Log On tab.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.