In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to realize the remote communication between Java and .NET in JNBridge bridging mode. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
The history of distributed development
Using Remote to call remote objects to realize communication between server and client is a common way of network development. In. Net and Java development, there is enough support for Remote remote objects (friends who are interested in Remote remote object calls are welcome to refer to the use of remote objects to achieve distributed development).
Since 2003, there has been widespread distributed development of .NET Remoting remote object calls in .NET. NET Remoting is mainly used to manage synchronous and asynchronous RPC sessions across application domains. By default, Remoting can communicate information using HTTP or TCP protocols and exchange data using XML-encoded SOAP or binary message formats. The .NET Remoting provides a very flexible and extensible programming framework and can manage the state of objects. After the introduction of Framewok2.0, WCF appeared on the scene, which is the product of various types of communication, such as. NET Remoting remote object, TCP/IP socket, Web service, MSMQ,P2P point-to-point and so on. WCF brings remote communication to another level.
In the aspect of Java, it also has strong support for remote communication. The RPC (Remote Procedure Call Protocol) protocol defined by it is a remote procedure call protocol, which can obtain the calculation result from the service requested by the remote computer through the network. It does not need to know the underlying network technology protocol to use communication methods such as TCP or UDP to transfer information data between programs. In the network communication model, RPC spans the transport layer and the application layer. RPC makes distributed development easier for the system. However, RPC communication does not realize the object-oriented development principle, and RMI (Remote Method Invocation) remote method invocation is a mechanism that computers use remote objects to call each other to achieve communication. With the object-oriented development mode and using RPC protocol, it enables the objects of the server and the client to be called remotely.
However, there is a drawback in the communication between .NET Remoting and RMI, that is, the restriction on the development language, no matter which mode of communication is used, the server and the client must support the same development language. It is a frustrating news that you cannot cross the limits of the development language in the process of communication. Because in large-scale development projects, different languages are often integrated to develop different modules. Using Remote for distributed development can improve the efficiency of communication, but it is limited. In this regard, the major development companies have made positive contributions to the development of integrated development tools such as J-Integra (also known as Ja.NET), IIOP.NET (Internet Inter-Orb Protocol) and JNBridge, which provide sufficient support for the mutual call of Remote remote objects between .NET and Java. The following is a detailed introduction to "JNBridge implements the interoperation between .NET and Java".
Overview of JNBridge
JNBridge is a leading product of Java interoperability with .NET. With JNBridge technology, Java and .NET code can share objects without cross-compilers. All Java code runs on JVM, while .NET code runs on CLR. Under this scheme, JVM and CLR can run on different machines, on different processes of the same machine, or even on different application domains of the same process. After years of development, JNBridge has released JNBridgePro 5.0 and JNBridgePro 5.0 with more powerful features.
Support for cross-platform transactions between ava and .NET
Support for Microsoft Visual Studio and Eclipse plug-ins
Compatible with Windows 7
The integration of cross-platform transactions is mainly transparent to users.
'rollback'- the termination of either party will cause the actions of both parties to be rolled back
JNBridge supports .NET To Java and Java To .NET services, and can communicate with TCP, HTTP, SOAP and other protocols. Here is a simple development example of "Java calling .NET" to introduce the functions of JNBridge.
JNBridge configuration
First of all, you can download the program from JNBridge's official website http://www.jnbridge.com/downloads.htm. After installing JNBridgePro 5.0, launch JNBProxy v5.1.exe, select Create new Java- > .NET Project, create a new project, and click Project- > Java Options to configure the system. First set the path of the native Java.exe application and jvm.dll assembly, and then set the path of jnbcore.jar and bcel.jar (in version 5.1, these two files exist in "/ JNBridge/JNBridgePro v5.1/jnbcore/"). * you can choose HTTP or TCP communication method (in this example, select TCP communication, the system default interface is 8085, you can also choose a custom interface). Click the "OK" button, and when the configuration is complete, the system will automatically generate a "/ JNBridge/JNBridgePro v5.1/jnbcore/jnbcore_tcp.properties" file to record the TCP configuration information.
.net server development
If you are using Visual Studio 2008 or Visual Studio 2010, the system will be aware of the existence of JNBridge. When you create a new project, you can directly create a new DotNetJavaProxies project. Here I want to show the conversion performance of JNBridge, so directly a new solution. Add a Model project, add the Person class, add the Serializable feature to Person, and be careful to remove unnecessary references, because references to Framework will become the corresponding package when converted.
Using System;namespace Model {[Serializable] public class Person {public int ID {get; set;} public string Name {get; set;} public int Age {set; get }}}
Add a Manager project, add the PersonManager class, and when testing, just put the virtual data in the DataSource.sour file.
Using System;using Model; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Collections.Generic;namespace Manager {public class PersonManager {/ / Virtual data source private List DataSource () {FileStream fileStream = new FileStream (". / DataSource.sour", FileMode.Open, FileAccess.ReadWrite); BinaryFormatter formatter = new BinaryFormatter () List personList= (List) formatter.Deserialize ((fileStream)); return personList;} / / get all Person public List GetList () {List personList= DataSource (); return personList } / / get the corresponding Person public Person GetPersonByID (int id) {foreach (Person person in DataSource ()) {if (person.ID = = id) return person;} return null;} according to the input ID
Add a ConsoleApplication as the startup project, add a reference to JNBShare.dll in the project (file path "\ JNBridge\ JNBridgePro V5.1\ 4.0-targeted"), and then add the configuration file
Config file
* start the service
Using System;using com.jnbridge.jnbcore;namespace NET_Service {class Program {static void Main (string [] args) {Console.WriteLine (".NET Start!"); / / start the .NET side service. Note that you must add a reference to JNBShare before you can use com.jnbridge.jnbcore.DotNetSide DotNetSide.startDotNetSide (); Console.ReadKey () / / disable the .NET side service DotNetSide.stopDotNetSide ();}
Generate conversion layer code
Open JNBridge, select "Add class from assembly files" on the toolbar, and add Model.dll,Manager.dll and mscorlib.dll respectively (this assembly exists in "C:\ Windows\ Microsoft.NET\ Framework\ v4.0.30319\" and contains important namespaces such as System,System.Collections,System.IO)
After selecting the necessary classes, press "Project- > Build", and the system will choose to put the class generation pairs in .NET into the Proxy.jar proxy package.
Java end development
Create a new Java project, reference the newly generated agent package Proxy.jar, as well as jnbcore.jar and bcel-5.1-jnbridge.jar (in version 5.1, these two files exist in "/ JNBridge/JNBridgePro v5.1/jnbcore/"), copy JNBridge's TCP configuration file jnbcore_tcp.properties into the bin folder, and develop a test side. It is worth noting that when generating the Proxy.jar code package, you must add a reference to the space of these common classes such as System.Collections.Generic,System.String, otherwise, you will not be able to call these common classes such as System.Collections.Generic.List in .NET in Java. Because there is a conflict between class names in the face of commonly used classes such as List in Java, System.Collections.Generic.List will be named System.Collections.Generic.List_1 in Proxy.
Package com.jnbridge.Javaclient;import com.jnbridge.jnbcore.*;import System.Collections.Generic.*; / / references the proxy class import Manager.*;import Model.* in the System.Collection.Generice.* space in the Proxy.jar package Public class Test {/ * * @ param args * / public static void main (String [] args) {/ / TODO Auto-generated method stub try {/ / register JNBridge's TCP configuration file jnbcore_tcp.properties DotNetSide.init ("E:\ Java Projects\\ JNBridge Java\ Java Client\\ bin\\ jnbcore_tcp.properties"); PersonManager personManager=new PersonManager () / / Note that this List_1 is the proxy class of System.Collections.Generic.List in the Proxy.jar package, not the List class List__1 personList=personManager.GetList () included in JDK; if (personList.Get_Count ()! = 0) {/ / Note that the Get_Count () method is the GetCount () method for (int nomenclature) of the System.Collections.Generic.List proxy class in the Proxy.jar package
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.