views:

297

answers:

6

I have some delphi code which, given a list of items, calculates the total price taking into account any special deals that might apply.

This code is non-trivial to rewrite in another language.

How should I set it up to communicate with a website running on the same server? The website will need to ask it for a price every time the user updates their shopping cart. It's possible that there will be multiple concurrent requests.

The delphi code needs to maintain an in-memory list of special deals, periodically refreshed from a database. So it cannot simply be executed every time or anything as simple as that.

I don't know what the website is written in, or even which http server it runs under, so I'm just looking for ideas or standard methods.

+3  A: 

It sounds like the win32 app is already running as a Windows Service on the box. So, if you can't modify that service, you are going to have to deal with whatever way it wants to accept and respond to requests. This could be through sockets or some higher level communication protocol like web services.

You could do a couple of things. Write an assembly that knows how to communicate with the service and have your web site use that assembly. Or you could build a shim service that knows how to communicate with the legacy service, but exposes communication over higher level protocols such as web services. Either way will have the benefit of hiding the concurrency, threading and communications issue behind an easy to call interface, but the latter will make communicating with the service easier for everyone going forward.

JP Alioto
It's currently part of a larger application, but can be torn out and turned into a windows service, or anything else it needs to be. It does not yet communicate in any way with other processes.
Blorgbeard
Okay, then definitely look at cracking it out into a Windows Service and giving it a WCF communication layer. That way, it can stay in memory, grab what it needs from the DB periodically and offer a nice interface to other applications for the purpose of data access.
JP Alioto
+2  A: 

It doesn't matter what web server or OS the existing system is running under. What matters is what you want YOUR code to run under. If it is windows then the easiest solution would be to use WebBroker and write a custom ISAPI application, or use SOAP to expose web services. The first method could be used if you wanted to write a rest like API for instance, the second if your web application has the ability to consume web services.

Another option, if you are running both on the same box under IIS, is to create a COM/Automation object which you then invoke via server side scripting (ASP). If the application is an ASP.NET application, then I would use PRISM to port your code into an assembly.

skamradt
+2  A: 

If you can modify the delphi app to take an XML request and respond with an XML answer over a TCP socket (ideally using the HTTP protocol), you will be able to make it interoperate with most web server frameworks relatively easily. But the exact details of how to make that integration happen will depend on the language/framework it was written in.

If the web server is on windows you can compile your delphi app as a DLL that can return XML or HTML, taking parameters as part of the URL or a POST operation. Some details on making a Delphi DLL for web servers are here.

kevin42
+1  A: 

Torn this app into Windows Service. Write Web Service that will communicate with your windows service. You should spend some time designing your Web Service, because this Web Service is going to be your consistent interface, shielding old Delphi app. So in the future whenever you will want to write web app, mobile app, or whatever you will imagine, you will have one consistent interface – XML Web Service.

smok1
+2  A: 

I have done this with a quite complicated workers compensation calculator. I created a windows service using RemObjects Sdk. The calculations are exposed as a soap method so it can be accessed by nearly anything.

It's not necessary to use RemObjects in the service but it makes it much easier to do as it handles a lot of the underlying plumbing. The clients don't need RemObjects, they just need to be able to call soap methods. Nearly any programming langugae can do that.

You could also create an isapi dll for IIS that exposes a soap interface. This would be useful if other websites on different servers needed access to the methods. However I have handled this in my case by opening a port in the firewall to access my windows service.

There is a lot of examples on the web. A couple of places to start reading are About.Com and Dr Bob.

SeanX
A: 

If you can make it a service (but not a library), you have to do inter-process communication somehow - there are a few ways to do this on Windows:

  • Sockets directly which is hardest since you have to do marshalling/auth yourself
  • Shared Memory (yuck!)
  • RPC which works great but isn't trivial
  • DCOM which is easier but a pain to configure
  • WCF - but can you call it from your Windows Service written in Delphi?
  • Remi Lemarchand