|
-
July 20th, 2009, 12:21 PM
#1
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?
-
July 20th, 2009, 02:22 PM
#2
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)
-
July 20th, 2009, 03:02 PM
#3
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.
-
July 21st, 2009, 06:55 AM
#4
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
-
July 21st, 2009, 07:15 AM
#5
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.
-
July 21st, 2009, 11:16 AM
#6
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?
-
July 21st, 2009, 11:27 AM
#7
Re: Exposing C# types from a windows service
I'd go with hosting the WCF service inside the Windows service.
-
July 21st, 2009, 11:32 AM
#8
Re: Exposing C# types from a windows service
 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).
-
July 22nd, 2009, 01:46 AM
#9
Re: Exposing C# types from a windows service
 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 ?
-
July 22nd, 2009, 01:48 AM
#10
Re: Exposing C# types from a windows service
 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.
-
July 22nd, 2009, 02:10 AM
#11
Re: Exposing C# types from a windows service
 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.
-
July 22nd, 2009, 09:28 AM
#12
Re: Exposing C# types from a windows service
 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
 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.
-
July 22nd, 2009, 10:27 AM
#13
Re: Exposing C# types from a windows service
 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.
-
July 22nd, 2009, 10:31 AM
#14
Re: Exposing C# types from a windows service
 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.
-
July 23rd, 2009, 12:17 AM
#15
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..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|