CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Feb 2002
    Posts
    98

    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?

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    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)

  3. #3
    Join Date
    Jul 2006
    Posts
    297

    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.

  4. #4
    Join Date
    Feb 2009
    Location
    Atlanta, GA
    Posts
    17

    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
    Scott Knake
    Custom Software Development
    Apex Software, Inc.

  5. #5
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    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.

  6. #6
    Join Date
    Jul 2009
    Posts
    7

    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?

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Exposing C# types from a windows service

    I'd go with hosting the WCF service inside the Windows service.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Exposing C# types from a windows service

    Quote Originally Posted by vcdebugger View Post
    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).

  9. #9
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Exposing C# types from a windows service

    Quote Originally Posted by Arjay View Post
    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 ?

  10. #10
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Exposing C# types from a windows service

    Quote Originally Posted by Arjay View Post
    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.

  11. #11
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    Re: Exposing C# types from a windows service

    Quote Originally Posted by sknake View Post
    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.

  12. #12
    Join Date
    Jul 2006
    Posts
    297

    Re: Exposing C# types from a windows service

    Quote Originally Posted by vcdebugger View Post
    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 View Post
    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.

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Exposing C# types from a windows service

    Quote Originally Posted by vcdebugger View Post
    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.

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Exposing C# types from a windows service

    Quote Originally Posted by vcdebugger View Post
    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.

  15. #15
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    460

    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
  •  





Click Here to Expand Forum to Full Width

Featured