Exposing a .Net Service
I have written a Windows Service in .Net and I want to expose the classes to be called by other .Net code. Specifically, I have an API that I want to expose via a DLL that will be placed in the GAC, and I want the DLL in the GAC to use the classes of the .Net Windows Service. I need this architecture as the code in the Windows Service needs to be run as a different user/account as the caller of the API (the account would be created at install time).
My plan was to expose the Windows Service classes via COM (regasm.exe to register and tlbexp.exe to create the type library), and then call the classes in the GAC DLL via COM (imported via tlbimp.exe). However I get the following error from tlbimp:
TlbImp : error TI0000 : System.Runtime.InteropServices.COMException - Type library '' was exported from a CLR assembly and cannot be re- imported as a CLR assembly.
This 开发者_StackOverflow社区implies to me that my method is not going to easily work. I can only think that I might need a C++ DLL as a bridge for my GAC DLL to invoke the COM calls, but this seems like a nasty solution.
I am basically looking for suggestions. Does anyone know how to expose classes of a Windows Service written in .Net to other .Net code?
You might want to have a look at using Remoting
- How To Host .NET Remoting Objects in Windows Service Application
- How to Use .Net Remoting Using C#
- Remoting in C#
I would put all the Windows Service logic in a separate DLL (e.g. x.dll). Define an interface for your classes in x.dll. Add Reference in both the Windows Service and the other .Net project to the project of x.dll. This way you can achieve reusability.
精彩评论