Exposing C# types from a windows service
How can I expose a class or an interface from a windows service written in C# and call its methods and properties from a client?
Re: Exposing C# types from a windows service
I doubt if that can be done. I would ideally not put any types within the Windows Service. I would create a separate Layer that will hold these classes. A Class Library is a better option and this can be accessed from any type of Client (Win Forms, Web Forms, another Service, etc)
Re: Exposing C# types from a windows service
You need to put the code in a Class Library and include that as a reference in the client. Then you can take advantage of .NET remoting or WCF to call methods in the service through a client.
Re: Exposing C# types from a windows service
If you can get ahold of the assembly where the types are defined you could load them but this is not ideal and I do not recommend it. You can rename the Service.exe to Service.dll and add it as a reference in your project. After all -- executables are just class libraries with an entry point :)
Re: Exposing C# types from a windows service
Instead of service write them in a COM server based dll and use it in your client.
Re: Exposing C# types from a windows service
I second WCF (or WS / remoting). After all, it is a service you're writing, right? Exposing the assembly would negate the purpose of the Windows Service, wouldn't it?
Re: Exposing C# types from a windows service
I'd go with hosting the WCF service inside the Windows service.
Re: Exposing C# types from a windows service
Quote:
Originally Posted by
vcdebugger
Instead of service write them in a COM server based dll and use it in your client.
If you went this route, you'd most likely want to go with a COM server exe; otherwise each of the clients consuming the COM object would have a separate copy of the COM dll (rather than one server/many clients). Not sure about the COM route though - it was great in its day or in the non-managed world, but the managed world has other options (that don't have the security restrictions that COM or DCOM has).
Re: Exposing C# types from a windows service
Quote:
Originally Posted by
Arjay
If you went this route, you'd most likely want to go with a COM server exe; otherwise each of the clients consuming the COM object would have a separate copy of the COM dll (rather than one server/many clients). Not sure about the COM route though - it was great in its day or in the non-managed world, but the managed world has other options (that don't have the security restrictions that COM or DCOM has).
thanks for the information. But how can we access the methods/objects from a COM server exe similar to COM server dll from the client side ?
Re: Exposing C# types from a windows service
Quote:
Originally Posted by
Arjay
I'd go with hosting the WCF service inside the Windows service.
can you pls throw some more light on this WCF and (or WS / remoting). I am bit new to this.
thanks in advance.
Re: Exposing C# types from a windows service
Quote:
Originally Posted by
sknake
If you can get ahold of the assembly where the types are defined you could load them but this is not ideal and I do not recommend it. :)
can you pls explain how exactly to load an assembly on the client side. Any link providing this info would be helpful.thanks in advance.
Re: Exposing C# types from a windows service
Quote:
Originally Posted by
vcdebugger
can you pls throw some more light on this WCF and (or WS / remoting). I am bit new to this.
thanks in advance.
WCF Tutorial
Quote:
Originally Posted by
vcdebugger
can you pls explain how exactly to load an assembly on the client side. Any link providing this info would be helpful.thanks in advance.
If you're using VS2008 or VS2005 just right click where it says references, click add reference, then find the DLL you're looking for and add it to the project.
Re: Exposing C# types from a windows service
Quote:
Originally Posted by
vcdebugger
thanks for the information. But how can we access the methods/objects from a COM server exe similar to COM server dll from the client side ?
This is getting off topic, but... In C++, one way to consume a COM server exe on the client is to import the tlb file. Depending on the type of interface, you may also have to generate a proxy. An excellent book on the subject is Beginning ATL 3 COM Programming.
Re: Exposing C# types from a windows service
Quote:
Originally Posted by
vcdebugger
can you pls explain how exactly to load an assembly on the client side. Any link providing this info would be helpful.thanks in advance.
Monolin already has answered this, but I'd also recommend getting a basic C# book and working through the exercises. There are a few 'step by step' or 'learn C# in xx days' books that would be a fine starting point.
Re: Exposing C# types from a windows service
thanks Arjay and monalin for all the info. It is helping me to learn C# very quickly..