Call .NET DLL compiled under Mono from Grails Application or use SOAP?
Part of my project wrote all their code in C#. Our web application is in Grails and needs to access their code. The interface for what we need is very simple (pass a file name as a String for example). I can compile it with Mono, as our environment is *nix based, but I'd like to avoid setting up ASMX web services with mod_mono and just call the dll with JNA or J开发者_高级运维NI. Is this possible and does anyone have good examples of doing it? Or is the simplest option going with setting up WS or some other RPC mechanism?
I don't have experience with either of the following but since Grails runs on the JVM these may work for you. I'm not sure how using Mono will affect your results. jni4net is designed to easily allow you to call .net code from Java. Another choice would be to run your Grails app using IKVM as the virtual machine. I'm not sure how well this would work though since IKVM does not support all features of the standard Java virtual machine. For info on calling Mono code from Java see this link. For other possible options see this question All of them should be usable since Grails runs on the JVM but using Mono instead of the normal .net platform may cause other issues.
I actually ended up doing something which normally I consider terrible, but seems to be the easiest. I have a .Net assembly that I can bring in as a DLL to my own .exe file that runs in Mono. I will end up just calling this from a Grails service by using the information from Codehaus. In my .Net exe I will return a String to STDOUT that I can marshal using Groovy's Eval capabilities like so (simplified):
// something like ['mono', "/opt/external/dotnet.exe", "parm1"]
def command = getCommandBasedOnSystem(exePath, urlPath)
def proc = command.execute()
// STDOUT: [prop1:"test", prop2:"something"] as HashMap
def object = Eval.me(proc.in.text)
// Processing based on object
I'm sure this isn't ideal but for my project this seems to be the most painless way without derailing how our application runs.
精彩评论