none
app interface talking to service RRS feed

  • Question

  • Hi guys

     

    what I am trying to implement is I have a server running as windows service, the server will launch as soon as the machine turn on, and I have application interface, when I start this app, I hope it can connect the service and talk to it, like get or set some info to control service, I know how to bulid a service and application, but how to implement the communication between them? how to get service instance from application, and when I close app, it does not bother service anything, just lose the app interface, service is still running in back

     

    Thanks

     

    btw: all those projects are built on .net framwork with c#

    Thursday, May 29, 2008 3:51 PM

Answers

  • Hi,

    There is huge amount of ways how to do it: you can host WCF server in your Windows Service and use appropriate WCF client in your desktop application; if .NET 3.0/3.5 is not suitable for your requirements, you can host .NET Remoting Server in your Windows Service and .NET Remoting Client in your desktop application; you can even host ASMX Web Service in your windows service using WSE and SOAPHTTPClientProtocol in your client application....
    Vitaliy Liptchinsky
    • Marked as answer by Bruno Yu Tuesday, June 3, 2008 6:41 AM
    Friday, May 30, 2008 7:08 AM
  • Malcolm,

    Since all clients of your windows service will be written in .NET and communication between client applications and windows service will be within local network, I believe .NET Remoting would be the best choice here.
    Vitaliy Liptchinsky
    • Marked as answer by Bruno Yu Tuesday, June 3, 2008 6:41 AM
    Friday, May 30, 2008 2:34 PM
  • Agreed.  .NET Remoting using an IpcChannel is the best way.  It is well documented in the MSDN library.
    Hans Passant.
    • Proposed as answer by Bruno Yu Tuesday, June 3, 2008 6:42 AM
    • Marked as answer by malcolmxu Tuesday, June 3, 2008 8:14 PM
    Saturday, May 31, 2008 5:25 AM
    Moderator
  • Hi Vitaliy

    I finaly solve this problem by adding following code in server part, I think for service i may have to config it by code inside, it is not controlled by app.config.

    IDictionary prop = new Hashtable();
    prop["portName"] = "test";
    prop["authorizedGroup"] = "Everyone"

    IpcChannel channel = new IpcChannel(prop, null, null);
    ChannelServices.RegisterChannel(channel, false);

    thanks so much for your help again

    Cheers!
    Malcolm
    • Marked as answer by malcolmxu Tuesday, June 3, 2008 8:14 PM
    Tuesday, June 3, 2008 8:13 PM

All replies

  • Hi,

    There is huge amount of ways how to do it: you can host WCF server in your Windows Service and use appropriate WCF client in your desktop application; if .NET 3.0/3.5 is not suitable for your requirements, you can host .NET Remoting Server in your Windows Service and .NET Remoting Client in your desktop application; you can even host ASMX Web Service in your windows service using WSE and SOAPHTTPClientProtocol in your client application....
    Vitaliy Liptchinsky
    • Marked as answer by Bruno Yu Tuesday, June 3, 2008 6:41 AM
    Friday, May 30, 2008 7:08 AM
  • Hi Vitaliy

    Thanks for your reply, very helpful

    can you give me some suggestions? my whole design is like this

    service work as server to talking some clients,

    desktop app with GUI, user can launch it to see some info and do some action to service, let it work with its client

    asp web app works similar as desktop app, user can do as same as desktop app does to service, let it work same way.

    so, my service will talk both desktop app, and web app, in this case, which way is better to go? I want to use Remoting Server, is it a good choice?

    Cheers
    -Malcolm

     

     

    • Edited by malcolmxu Friday, May 30, 2008 2:07 PM typo
    Friday, May 30, 2008 2:04 PM
  • Malcolm,

    Since all clients of your windows service will be written in .NET and communication between client applications and windows service will be within local network, I believe .NET Remoting would be the best choice here.
    Vitaliy Liptchinsky
    • Marked as answer by Bruno Yu Tuesday, June 3, 2008 6:41 AM
    Friday, May 30, 2008 2:34 PM
  • Agreed.  .NET Remoting using an IpcChannel is the best way.  It is well documented in the MSDN library.
    Hans Passant.
    • Proposed as answer by Bruno Yu Tuesday, June 3, 2008 6:42 AM
    • Marked as answer by malcolmxu Tuesday, June 3, 2008 8:14 PM
    Saturday, May 31, 2008 5:25 AM
    Moderator
  • Thank you very much, Vitaliy and Hans

    Cheers!
    -Malcolm
    Monday, June 2, 2008 2:03 PM
  • Hi Vitaliy & Hans

    I am trying to do some test before to implement this in my project. but I got some problem.

    I simply use the sample code, that is very simple, server, remote object and client, using ipcChannel, it works fine
    and then I don't change client, create a windows service project, put remote server ipcChannel code into it, and create another app use ServiceController to control the service, after I install the service, I can see the service is there, and then use ServiceController to start it, I can see the service is running, but when I launch client to talking to the remote server in the service, I got error, seen no remote server is there.

    I register ipcChannel in OnStart in Service, any suggestion?

    Thanks
    -Malcolm
    Tuesday, June 3, 2008 2:40 PM
  •  Hi Malcolm,

    Sorry, but at first point it's pretty hard to identify the reason of error. Have you tried to debug your Windows Service? There could be possible configuration exceptions.
    Vitaliy Liptchinsky
    Tuesday, June 3, 2008 3:10 PM
  • Hi Vitaliy

    Thank you quickly to reply me

    the error is "Failed to connect to an IPC Port: Access is denied"

    I google this msg and get some help, add my app.config like this, but it des not work either,same error msg, it seem if I put remote ipc channel in window service, it is different.

    <?xml version="1.0" encoding="utf-8" ?>

       <configuration>

    <system.runtime.remoting>

    <application>

    <service>

    <wellknown mode="SingleCall" type="RemoteServer.RemoteObject, Server" objectUri="RemoteObject.rem" />

    </service>

    <channels>

    <channel ref="ipc" portName="serverChannel" authorizedGroup="Everyone"/>

    </channels>

    </application>

    </system.runtime.remoting>

    </configuration>

    Tuesday, June 3, 2008 7:48 PM
  • Hi Vitaliy

    I finaly solve this problem by adding following code in server part, I think for service i may have to config it by code inside, it is not controlled by app.config.

    IDictionary prop = new Hashtable();
    prop["portName"] = "test";
    prop["authorizedGroup"] = "Everyone"

    IpcChannel channel = new IpcChannel(prop, null, null);
    ChannelServices.RegisterChannel(channel, false);

    thanks so much for your help again

    Cheers!
    Malcolm
    • Marked as answer by malcolmxu Tuesday, June 3, 2008 8:14 PM
    Tuesday, June 3, 2008 8:13 PM
  • hi guys

    one more question about remote server, right now I have remote server working in windows service, but sometimes, my server has something need to notify client, can I raise an event from server and client can handle it?

    Thanks
    -Malcolm
    Wednesday, June 4, 2008 2:47 PM
  • Hi Malcolm,

    Sure, it is possible.

    Vitaliy Liptchinsky
    Wednesday, June 4, 2008 3:18 PM
  • Hi Vitaliy

    this is cool, can you give me some doc link or sample link? I have not found it

    Thanks
    -Malcolm
    Wednesday, June 4, 2008 3:45 PM
  • Firing events through .NET remoting is quite tricky and hard to get right.  Please start a new thread in the .NET Remoting forum.
    Hans Passant.
    Wednesday, June 4, 2008 4:28 PM
    Moderator
  • Hi Vitaliy Liptchinsky

    Very Thanks

    I hope best for u...

    Tuesday, September 7, 2010 10:55 AM