C# dll which is inter-operable with php and java - c#

I need to create a dll in C sharp which is interoperable with php and Tomcat/Java webservices.
Will the normal C# class library help me for this?
Thanks,
John

Will the normal C# class library help me for this?
You could expose the class library as WCF service using the interoperable basicHttpBinding which could be consumed by PHP and Java.

I'm interpreting that as "I need to consume a web-service", in which case either use wsdl.exe, or use the "Add Web Reference..." / "Add Service Reference..." option in Visual Studio. Either approach results in appropriate proxy classes being created that represent the target service's WSDL.
This is data/protocol interoperability; note that the dll itself won't be directly usable from java / php.

Your question is a bit unclear on which way to "operability" goes. I assume you are talking about making a C# class library that will call these web services, which happens to be implemented in PHP/TomCat/Java.
And yes, the .Net Framework have excellent support for calling http endpoints. Also, if these endpoints happen to return XML data, there is excellent support for working with that too. If the services are RESTful, you even have support for that.
Update: since my initial assumption was wrong, and the interoperability must go from PHP/Java to .Net I suggest looking at how these languages can interop with COM. .Net classes can be exposed as COM classes, which further can be consumed by PHP and Java.

Maybe Im wrong about what is the question, but you can use c# assemblies in php with the DOTNET class:
http://php.net/manual/en/class.dotnet.php

Related

Allowing my application to be used by other applications

I would like to know how to allow my C# application to be used from others' own applications.
Is making the relevant classes public enough for this purpose? Shall they be able to put a reference in their projects to my .exe and use my public classes freely? Shall they only be able to use it from .NET applications?
What else should I take into account? Any security issues maybe?
Your .Net dlls can be used by other .Net applications. You can separate the logic part of your code from the interface, and put the logic in "Library" projects that will be compiled as Dll files that can be used in a .Net application by adding references to them.
If you want to allow non .Net apps to used you can use COM Interop:
Wikipedia - COM Interop
COM Interop C# Tutorials
You can also use WCF services as CSharpVJ says.
Create a wrapper WCF service and expose your exe application thru' those WCF services, and it will be available to almost all clients based on even other platforms like Java, Python, Ruby and more depending on which settings you use inside your WCF Service..
WCF provides a service based model to communicate with other applications based on .Net and other platforms.
WCF is explained at this article in MSDN
You could always just make the sourcecode public on https://github.com/ for example.
That would other people allow to view and edit your sourcecode compeltly, which might be even better than a WCF service

C# app create objects from Java classes?

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.

Call Java Method from API in .NET

I have a Java API in jar file with some dependencies from other jar files.
Is there any way to call a specific method from this API, like using PInvoke from .NET?
Here you go :) I've used it myself and was very please with the implementation.
IKVM: Using Java API's in .NET Applications
(1) If you just want some libraries
from Java.
(2.1) If you have access to
the code.
(2.2) Last resort,
dynamically load the Java into .Net
(interpreter)
I don't think it will be an easy task to interoperate .net and java. May be you could use sockets, and use them to send messages from one environment to another. It is just an idea, though.
EDIT:
I have found some libs that say they can do this:
http://www.jnbridge.com/
http://www.codeproject.com/KB/dotnet/Espresso.aspx
You can use CORBA to "call" java methods from .NET.
For .NET here you can find some CORBA libraries.
Java SDK includes CORBA capabilities so you don't have to download 3rd party libraries.

Silverlight - Send/Receive Data at runtime with JAVA

Yesterday I asked about what technology should I use to create dynamic web content here:
PHP, AJAX and Java
The suggested methods were JSP, JQuery, etc. But I thought maybe because I'm a .Net developer and I don't have any experience in web development but I have experience in WPF and C#, maybe I should go with Silverlight but the main problem here would be how can I communicate with the core part of my system which is implemented in Java?
So the main question would be: What is the best [and easiest to learn] method to send a piece of data to the Java part, get the result and use it in silverlight? A tutorial or simple example would be nice.
Thanks a lot in advance.
You should use Java Web Services as stated. Use WCF to invoke the Java WS by adding a Service Reference in Visual Studio by its url, then use the proxy classes generated automatically (located in Reference.cs) to invoke the WS. This is easy but remember SilverLight WS invocations are always asynchronous, so you must cath the OnCompleted event to get the results of the invocation. WS are slow but if the machines are in the same LAN, invocation could take a few milliseconds.
I think pipes are not your solution as SilverLight executes in a Sandbox and have many restrictions on what you can do.
This will depend on many factors, however a relatively easy approach would be to use Java Web Services. On the .NET side, WSDL will be picked up and transformed into proxy class by WSDL.exe from the Windows SDK. If, however, these two systems are on the same server (and intend on staying this way), you may decide to use pipes.

Interacting with java code from C#

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.

Categories