views:

22

answers:

1

I have a database client application. Some people will run multiple instances (i.e. processes) of it to connect to different databases simultaneously. I'd like to have this app accept a custom URI scheme for simple commands such as 'open record 123'. The URI contains the database it pertains to, so, depend on the contents of the URL, one particular process is 'eligible' to handle it.

As such, I've decided to create an additional app for URI handling that 1) isn't constantly running, but only invoked through Windows when a URI is clicked somewhere, and 2) finds the right client and passes the URL on to it. I've used an IpcServerChannel on the database client, and an IpcClientChannel in the URI handler, so that the URI handler can ask the client which database it's responsible for.

How do I handle this for multiple clients, though? How can the URI handler 'discover' which clients (i.e. IPC servers) are currently running, and how to connect to them through IPC?

+1  A: 

A windows service that each client app registers with when it starts up would be a fairly reasonable way of handling this scenario as it could also take care of URI processing.

A couple of things you may want to think about though:

  • How will the service handle multiple users being logged into a single PC
  • How will the service handle instances of the client app that are force terminated or crash

To respond to your comment about not wanting the URI handler constantly running:

If you have the client application / URI Handler (in a similar way to the way .msi installation triggers the Windows Installer service to start, perhaps) start the service if it's not currently running, and have the service terminate itself when it no longer has any running clients you'll achieve that requirement.

Rob
That's one way, but I would prefer not to have the URI handler constantly running. (I'm not even sure a Windows Service *can* act as an URI handler?)
Sören Kuklau
@Sören, I've added to the answer to try and address your concerns =)
Rob
Sounds a little more complex than I'd hoped for, but I'll probably go with that — thanks!
Sören Kuklau
Just to follow-up that I did go with this approach — each workstation gets a service that clients register with and that ships with a URL handler that launches as a separate process. Sounds like a lot of overhead, but works just fine. Thanks again.
Sören Kuklau
@Sören Kuklau, glad my answer helped :) I'd be interested to see how you implemented this if there's a version of the code you wrote that you can publish anywhere without giving away any company confidential information =)
Rob