有没有一种方法可以从Java代码中调用C#方法?

huangapple go评论56阅读模式
英文:

Is there a way to call a C# method from java code?

问题

我有一段C#代码片段,用于读取一个非常旧的MS Access数据库。这是一个MS-Access 95数据库,在Java的UCanAccess库中不受支持。因此,我不得不切换到C#并从这里检索数据。在C#中完成的处理应在特定操作发生后被调用,而这些操作是在Java中完成的。因此,我希望能够从Java中调用C#方法,如果有可能的话。由于它连接到一个将其数据写入此访问数据库的设备,数据库不时会得到更新。

有没有办法从Java中调用C#方法?或者您是否对如何实现有任何其他想法?

英文:

I have a C# code snippet where I read a very old MS Access Database. It is a MS-Access 95 Database, which is not supported in Java's UCanAccess lib. So I had to switch to C# and retrieve the data from here. The process done in C# should be called after specific actions happen, which are done in Java. So I want to call the C# method from Java, if there is a possibility. The database gets updated every now and then because it is connected to an equipment which writes its data to this access database.

Is there a way to call the C' method from Java? Or do you have any other ideas on how to do it?

答案1

得分: 1

建立一个使用C#和.NET Framework的简单控制台应用程序。此应用程序只需访问数据库并返回数据。然后从您的Java应用程序调用此控制台应用程序。

此外,考虑使用C#和.NET Framework创建一个简单的REST服务,并从您的Java服务中使用它。如果您已经拥有某种微服务架构,这可以是一个选择。否则,可能会过于复杂。

英文:

Build a simple console application with C# and .NET Framework. This application should just go to the database and return data. Then call this console application from your Java application.

Additionally, consider creating a simple REST service with C# and .NET Framework and consuming it from your Java service. It can be an option if you already have some kind of microservice architecture. Otherwise, it can be overkill.

答案2

得分: 0

第三种方法是从C#代码构建一个DLL,并在你的Java代码中使用它。

英文:

Third alternative is to build a DLL from C# code and use it in your java code.

huangapple
  • 本文由 发表于 2020年9月24日 15:17:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/64041309.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定