0

We have a third party supplied application with a button that enables the opening of another application showing related data when pressed (these applications are made by completely different companies). However, the application with the button does nothing more than the equivalent of clicking a url with a query string of parameters and so initiates the default behaviour of widows in response which is to open a web browser pointing to the url (the url can be whatever we want).

The application we want to open in response is not a web application; it is just a standard windows desktop application.

The solution we have at current for this is to create a small self-hosted service using WebServiceHost in .Net framework 4.0 and to host this service in a windows form application, but without a form and instead display an icon in the tray when it is running (which will be all the time).

When the service is effectively called into it closes the browser web page that had been opened in response to the url and opens the desktop application populating the fields with the parameters supplied in the query string.

This all seems to work as required but it does not seem a very conventional way of doing things, in fact it would not be possible without WebServiceHost because it is the only thing we have that can respond to the url. We use a WebHttpBinding. We have looked at other things such as IPC, etc. but they all require IIS to be running on the user machines and that is not company policy. Ideally I would like to use a Windows service for hosting rather than a ‘tray application’ but WebServiceHost does not seem to work (respond) in that context.

What does anyone think of this rather unconventional way of doing things? Are they any security risks associated with hosting a service like this? Is there a better way of doing it?

The code involved is little more than:

webServiceHost = new WebServiceHost(typeof(Services.MyService), new Uri("http://localhost:8001/"));
webServiceHost.AddServiceEndpoint(typeof(Contracts.IMyService), new WebHttpBinding(), "/WindowsHost/MyService/");            
webServiceHost.Open();

(it might be necessary to add an empty WebHttpBehaviour) and then just a url like below will call into the service and initiate the method in the service (open notepad in this example).

http://localhost:8001/WindowsHost/MyService/OpenNotePad

public void OpenNotePad()
{
      Process.Start("notepad.exe");
}
  • You certainly can create a Windows Service that listens on a port. Look into OWIN for that. Can you configure the URL that the 3rd-party button uses? If so, you could register a pluggable protocol like myapp:// that runs your application. – Moby Disk Aug 7 '15 at 15:26
  • Is the application with a button a web application? There is no need to open up another web page using a url, in your scenario. All you have to do is send the right call to the WCF server, using the WCF libraries. – Frank Hileman Aug 18 '15 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.