Using C#, .NET3.5, Visual Studio 2008 and WCF on Windows VISTA SP1, I have written a service, service host (as a C# console application) and a client.
The service uses Microsoft.Offic e.Interop.Excel .Application to access an Excel file on the local hard drive, opens it (using Application.Wor kbooks.Open), reads out some data and the provides said data to the client.
Everything works perfectly when the Service Host is a C# console application. That is, the client invokes the call, the service host duly invokes the service, which in turn reads the Excel file and returns the expected data.
However, when the Service is wrapped as a Windows Service (so all the code is identical), Application.Wor kbooks.Open fails to open the file; debugging the service indicates that Excel returns an error "Cannot access the file...".
My original guess was that the Windows service was running in a lower trust situation. However, I have tried running the service under my own administrator account, allowed interaction with the desktop, granted the Service Full Trust (from VS 2008 and reinstalled the service), added a strong name key and anything else I can think of. But to no avail.
I even added code to the Service that opens a binary .dat file from the hard drive (not in Isolated Storage) and reads in some arbitrary values - this works fine under the console application and Windows Service, thereby proving the Windows Service has elevated trust.
When running with access to the desktop, I also set the Application.vis ible attribute to true, so I could interact with Excel and try to figure out what's going on. Sure enough, under the Windows Service, the Excel application starts, but all I can do is create a New workbook and type in it. The application won't let me Save it nor Open an existing workbook (hence, the Application.Wor kbooks.Open method fails from within the Windows Service).
In conclusion, the Windows Service itself clearly has elevated trust, as it can open, read, write and save to a local file on the hard drive (not in Isolated Storage). However, when the Windows Service calls Application.Wor kbooks.Open to interact with Excel, said COM object does not have the ability to do any file operations.
Guessing wildy, I imagine that the COM object that Excel.Applicati on uses to interact with Excel is perhaps under-the-hood being run in a separate thread that has lower priority.
Essentially I'm stuck at this point and would appreciate any guidance that is on offer.
Thanks in advance,
Robert
The service uses Microsoft.Offic e.Interop.Excel .Application to access an Excel file on the local hard drive, opens it (using Application.Wor kbooks.Open), reads out some data and the provides said data to the client.
Everything works perfectly when the Service Host is a C# console application. That is, the client invokes the call, the service host duly invokes the service, which in turn reads the Excel file and returns the expected data.
However, when the Service is wrapped as a Windows Service (so all the code is identical), Application.Wor kbooks.Open fails to open the file; debugging the service indicates that Excel returns an error "Cannot access the file...".
My original guess was that the Windows service was running in a lower trust situation. However, I have tried running the service under my own administrator account, allowed interaction with the desktop, granted the Service Full Trust (from VS 2008 and reinstalled the service), added a strong name key and anything else I can think of. But to no avail.
I even added code to the Service that opens a binary .dat file from the hard drive (not in Isolated Storage) and reads in some arbitrary values - this works fine under the console application and Windows Service, thereby proving the Windows Service has elevated trust.
When running with access to the desktop, I also set the Application.vis ible attribute to true, so I could interact with Excel and try to figure out what's going on. Sure enough, under the Windows Service, the Excel application starts, but all I can do is create a New workbook and type in it. The application won't let me Save it nor Open an existing workbook (hence, the Application.Wor kbooks.Open method fails from within the Windows Service).
In conclusion, the Windows Service itself clearly has elevated trust, as it can open, read, write and save to a local file on the hard drive (not in Isolated Storage). However, when the Windows Service calls Application.Wor kbooks.Open to interact with Excel, said COM object does not have the ability to do any file operations.
Guessing wildy, I imagine that the COM object that Excel.Applicati on uses to interact with Excel is perhaps under-the-hood being run in a separate thread that has lower priority.
Essentially I'm stuck at this point and would appreciate any guidance that is on offer.
Thanks in advance,
Robert
Comment