I have written a C# program which has to call two methods in an eclipse plugin process.
I need an idea on how to realize the communication between the C# process and the java process.
You could use Sockets or else Inter Process Communication (IPC) Structures (more here). The best one depends on what you are doing and how you are doing it, which is not something you are exposing in your question.
Maybe try this: Ikvm
its a JVM that's implemented in .net and it provide several tools to help the development.
Related
I want to use both C++ and C# in my application.
C# for GUI design and C++ for processing.
But I don't have any knowledge about this. How to communicate between them.
I don't know where I have to begin and research.
Someone can tell me the overview about this technology? And if someone have document about this topic, please give it to me.
I'm using Visual Studio 2010 for development.
Many thanks,
T&TGroup
The technology you are looking for is C++/CLI, a proprietary language extension for C++, that allows interaction with .Net code.
The basic idea is this: You write your C++ libraries as ever in portable ISO C++. Then you add a thin wrapper in C++/CLI for those C++ components you want to call from C# (or any other .Net language for that matter).
Just be aware that C++/CLI is only intended to write code for interaction with .Net. Don't be tempted to write the implementation in CLI as well, as you will end up with code that is not portable and probably a lot harder to maintain than the pure C++ version.
It depends on what the architecture of your application should be, you can for example create two different application one that is the core and another that is the GUI and communicate through messaging.
On Windows you can use Windows message queue for example, to let the two end point communicate with each other.
You can either use C++ CLI or native C++. C++ CLI is managed code and native c++ will be unmanaged by the CLR. The choice between the two depends on your usage. There are certain limitations with C++ CLI.
It depends totally on the architecture and requirement as well. You can write processing instructions in C++ (lib) use them in GUI. Can be done in VS 2010 as well easily
Can a C# app create objects defined in Java .class files?
Is any interop between C# and Java possible, with C# as the host language?
What you are looking for is a combination of PInvoke and JNI.
You will have to create classes in Java. Expose them via JNI. Access these through PInvoke in C#. You have a to and fro communication between C# to Java.
http://en.wikipedia.org/wiki/PInvoke
http://en.wikipedia.org/wiki/Java_Native_Interface
If you need direct instantiation you need JNBridge otherwise you can expose the Java program as a server and communicate with any RPC technology (TCP, http etc.)
I have used IKVM in the past. It works well for large projects, but might be too much for you. It all depends on where you're going with this. But if you want complete interop it's worth looking into.
Otherwise, if you an expain your intentions better someone might have a better idea.
I'm working on a project that uses an RFID reader, which only works with a library in C#. The thing is I'd really like to work with Java (develop the rest of the program, GUI, etc), and use the C# program just to ask the reader to read the information and return a string to the Java program.
So, is there a way I could do this?
Thanks in advance.
One way to approach this is to look at it as a problem of interprocess communication. There are a bunch of options (assuming Java has access to the necessary Windows API's which I'm assuming it does, but I'm not really a Java dev).
Named Pipes, TCP/IP, Filesystem, Mailslots, etc.
Here's a good article on some options: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx
Another option, which I don't know enough to speak about, is trying to load a .Net library into your java process.
Couldn't you use sockets?
They both do support it, but I never tried to do it between different languages.
Good luck.
If you don't mind delving too deep you could use the Java Native Interface to generate code to marshall calls from Java to C# and back again. You'd need to build a "bridge" in c/c++ (c++ is generally slightly easier).
This way you get in-process communication, which is the fastest way to work :-)
I would like to wrap a java application as a Windows Service using C#. I can do it easily using the Process class and calling Process.Start("java.exe", "args"), but doing this way I have 2 process, my service wrapper and the java process. I'm looking to fully wrap the java application, including the java process.
Does anybody here has done it or knows the best way to do this in C#?
The two basic approaches are to either run the Java application as a separate process, or to host the JVM directly, and use it to launch your application. There isn't a direct way to do this in C#, as the JNI interfaces for hosting are C++ interfaces only.
However, there are commerical products that allow you to do this directly from Java.
We've written a Java program which we are looking to use and interact with from C#. What are our options? Optimally it would be possible to compile the Java application as a library (.DLL) that we could reference from C# perhaps using P/Invoke. This, however, doesn't appear to be an option according to the first few searches online.
We opt to be able to use ASP.NET to built a search engine powered by the Java code, so if this opens up for any other options please let us know.
Sorry, you cannot call java code / classes Directly from C# code.
One way of doing this is to wrap up your java classes in a java Web Service and call classes indirectly through that web service interface in your C# code.
Another way is using
javareg.exe which exposes java classes as COM. You can find it at following location:
C:\Program Files\Microsoft VisualStudio\VIntDev98\bin\javareg.exe
Following posts might help as well
Calling Java Classes Directly from
.NET (uses runtime bridge)
Calling Java from Microsoft.NET
The simplest approach would probably be to publish the functionality of your java library as web services and add a web-reference from your asp.net application.
Java isn't meant to be embedded in another program, so you need a bridge. The most simple solution is to use a socket: Create a Java process which listens for commands on a socket. In the C#, send the commands to the socket and read the answers.
The main problem here is serialization but if you use XML, it's not such a big pain anymore. Try the built-in XML serialization (see this article) or custom frameworks like XStream or Simple.
It is certainly possible to wrap Java in a .dll, and has been a part of the core Java platform for over 10 years. JNI (Java Native Interface) has an interface for embedding a JVM in your code, meaning you can run Java classes using C-style linking. Note that this will require that you write a simple C wrapper, there are samples within:
http://java.sun.com/docs/books/jni/html/invoke.html#11202
As some of these other posts suggest, sometimes it's desirable to be less tightly coupled, so you may want to consider using another design. One option would be a simple database, where the Java application regularly polls for requests from the C# code. If you want tighter coupling, for things like call-backs, you can look at distributed interfaces.