Question: C # several methods to call Java
1. Publish Java interfaces through WebService. C # can be conveniently called.
2. Use C ++ to call Java through JNI, and C # To Call The C ++ Interface
3. Use the open-source library to directly use C # To Call Java. For details, click
4. Use IKVM to implement C # Call Java,
The reason for this is that my client needs to call the HBase interface (implemented in Java). At the beginning, I used the WS Method for calling. This method is simple and versatile. Later, I found the third method mentioned above and called it successfully. However, the buddy who wrote this library seems to have not maintained the library he wrote. There are several obvious bugs in it, in addition, the memory error will be reported during the loop call time. Because JNI is not familiar with it, the method will be abandoned. If you are interested in this method, you can improve it for him, again, this open-source library depends on jvm. dll, only 32-bit JavaJDK. The second and fourth methods have not been studied in depth.
In the end, I didn't use any of the above methods, but I used Thrift. Although it is a little slower than Java API, it is still within the acceptable range. Next we will go to the topic:
Preparation phase:
Generate Thrfit interface class:
1. Obtain the HBase. Thrift file from the HBase package. (.. \ Hbase-0.94.6.1 \ src \ main \ resources \ org \ apache \ hadoop \ hbase \ thrift in this directory)
2. Put the thrift-0.9.0.exe and HBase. Thrift files in the agreed directory (of course, they can be in different directories)
3. Go to the command line, and the Thrift-0.9.0.exe-gen CSharp HBase. Thrift directory is named gen-csharp.
Build a solution
The code of the prepared Project has been completed. Create a VS Project and introduce the source code Project of Thrift and the newly generated interface class.
Start the Thrift service of the Cluster
Hbase-daemon.sh start thrift port default 9090
Write test code