Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wrap a C library so that it can be called from a web service

We have a library with very complex logic implemented in C. It has a command line interface with not too complex string-based arguments. In order to access this, we would like to wrap the library so that it can be accessed with simple XML RPC or even straightforward HTTP POST calls.

Having some experience with Java, my first idea would be

  • Wrap the library in JNI/JNA
  • Use a thin WS stack and a servlet engine
  • Proxy requests through Apache to the servlet engine

I believe there should already be something simple that could be used, so I am posting this question here. A solution has the following requirements

  • It should be deployable to a current linux distribution, preferrably already available via package management
  • It should integrate with a standard web server (as in my example Apache)
  • Small changes to the library's interface should be manageable
  • End-to-end (HTTP-WS-library-WS-HTTP) the solution should not incur too much overhead, but reliability is very important

Alternatively to the JNI/JNA proposal, I think in the C# world it should not be too difficult to write a web service and call this unmanaged code module, but I hope someone can give me some pointers that are feasible in regards to the requirements.

like image 850
Kariem Avatar asked Feb 10 '10 20:02

Kariem


3 Answers

If you're going with web services, perhaps Soaplab would be useful. It's basically a tool to wrap existing command line applications in SOAP web services. The web services it generates look a bit weird but it is quite a popular way to make something like this work.

like image 73
wds Avatar answered Oct 13 '22 00:10

wds


Creating an apache module is quite easy and since your familiar with xmlrpc you should check out mod-xmlrpc2. You can easily add your C code to this apache module and have a running xmlrpc server in minutes

like image 22
jfarrell Avatar answered Oct 12 '22 22:10

jfarrell


I think you may also publish it as a SOAP based web service. gSoap can be used to provide the service interface out of the library. Have you explored gSOAP? See http://www.cs.fsu.edu/~engelen/soap.html

Regards, Kangkan

like image 36
Kangkan Avatar answered Oct 12 '22 23:10

Kangkan