Windows Service accessing COM through Interop

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Bunce (anonymous_at_discussions.microsoft.com)
Date: 06/09/04


Date: Wed, 9 Jun 2004 05:30:26 -0700

Hi all - bit of a confusing one..

I'm trying to setup a windows service which interacts
with some mapping software running on the same machine,
which exposes a number of interfaces through COM.

The service is meant to fire off this software upon the
changing of a text file on the server and for this I'm
using the FileSystemWatcher component. No problem there,
the FSW event fires fine when its meant to..

The problem is interacting with COM. Basically the
service needs to get a reference to a list of currently
running mapping processes, and from within that, fire off
a custom command within that application. This is all
performed through the exposed COM events provided by the
mapping software.

Strange thing is, this all works perfectly when I tested
it though a Windows Forms Exe, but as soon as I port
identical code to a service, I get a 'Server Execution
Error' when trying to get a referce to the
running 'mapping' applications, using this code:

Dim apps as New ESRI.ArcObjects.Core.AppRot

* Approt is the method which provides a hook into the
running mapping applications
* ESRI.Arcobjects.Core namespace is actually a .Net
assembly provided by the software manufacturers
specifically for .Net interop, however I've also tried it
by setting a reference to the original COM dll, and
having VS create the interop. Boh methods work in an
Windows Forms EXE but not a service.

Anyway, so what I'm wondering is if there is an
issue 'communicating' with running COM processes from
a .Net service, whereas there's no issue communicating
from a .Net EXE?

I assume it's a threading or context issue, although I've
scoured the Net for info on this and as yet have come up
empty.. I've tried running the service as both an STA and
an MTA with no difference. I've also tried running the
service under the same 'user account' that was logged in
when the EXE worked successfully but 'no banana'. So I
don't think it's a permissions issue...

Any ideas? I'm just about out of them.. Wondering if I
need to use 'Marshaling' somehow but am unsure how to do
it.. If I can somehow get the 'service' to act or
perform the same as the Windows Forms Exe then it will
hopefully work..

Thanks in advance,
Andrew



Relevant Pages

  • Re: HELP: VMS as an NFS client to Windows or Linux - primer please
    ... But I also have a proxy for both incoming and outgoing mapping my VMS ... 0,0 doesn't exist - so I deleted the mappings in Windows and started by creating a group mapping of 4 for system and 100 for users. ... By default, the anonymous UID/GID on windows is -2,-2. ...
    (comp.os.vms)
  • Windows CE Config.bib
    ... and OEMAddressTable in Windows CE. ... OEMAddressTable which specifies virtual to physical address mapping. ... So is NANDIMAGE for allowing XIP execution form Nand Flash? ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Windows CE Config.bib
    ... and OEMAddressTable in Windows CE. ... OEMAddressTable which specifies virtual to physical address mapping. ... So is NANDIMAGE for allowing XIP execution form Nand Flash? ...
    (microsoft.public.windowsce.platbuilder)
  • Re: AzMan Still the way to go?
    ... The thing to know with Windows authentication (IWA in IIS) in ASP.NET is ... simple approach is to create a simple mapping between AD groups and your ... I can use windows authentication IIS, and was actually planing on it. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Handheld GPS
    ... cheaper one without mapping? ... Mapping software could spare you the effort of constantly plotting your ... GPS position on a chart to visualize exactly where you are. ...
    (uk.rec.sailing)