Introduction
There is no doubt that .NET is much advanced than SWING, So if you need to make a Desktop application. Best Choice is .NET. Java has some advantages in different areas on server side, one of them is JMS. (Many people will not agree). I have tried to use the power of .NET as a client and integrated Java Webserices asynchronously with it, More over I have used JMS on webservices side to send messages to .NET client. Its just the beginning of a small framework which can be extended to make a full-fledged .NET, JMS interaction framework
Background
I had a SWING client/JMS application in java. My other application was in .NET, which also needed to receive messages from the JMS.
Technologies Used
- Asynchronous DOTNET Web services
- DOTNET Delegates
- Java Webservices - AXIS
- Java Messaging Service (JMS)
- HTTPConnectionFactory
How to run the application?
The Java web service is made using JBuilderX and is tested on JBoss 3.x. To run the application you need to run in the applications in the following sequence
- Java Web service.
Open the project in JbuilderX and run the server with the configuration "Start Web Services Server"
- .NET Client
Update the Web Reference
Run the application using Visual Studio .NET 2003
- Java JMS message publisher class. JMSChatPublisher
Open the project in JbuilderX and run the application with the configuration "Send messages via JMSPublisher"
In the console window, write messages and press enter. The messages will go through the webservice and will be shown in the textBox in .NET application. Above also shown the image of what is described.
Architecture Diagram
Using the code
Java side code
NOTE: The code is not optimized and no design patterns are included in it.
The following code is written in ReceiverWebService
which creates the JMSChatSubscriber
and calls the getSynchronousMessage
and waits for a response from the function.
public String getJMSChatPublisher() {
JMSChatSubscriber jmsChatSubscriber = null;
jmsChatSubscriber = new JMSChatSubscriber();
return jmsChatSubscriber.getSynchronousMessage();
}
.NET side code
Client calls the webservice asynchronously using RegisterJMS
and the response is received in the callback ServiceCallback
. After the message is received using EndgetJMSChatPublisher
. It again calls the RegisterJMS
to wait for the next message
public void RegisterJMS(NotifyMessage function)
{
em = new ReceiverWebServiceService ();
AsyncCallback cb = new AsyncCallback(ServiceCallback);
IAsyncResult ar = em.BegingetJMSChatPublisher(cb,em);
this.callFunction = function;
}
public void ServiceCallback(IAsyncResult ar)
{
string str = em.EndgetJMSChatPublisher(ar);
callFunction(str);
RegisterJMS(callFunction);
}
Conclusion
I have not implemented or showed the following cases, as they are pretty straight forward.
- .NET application as a sender - Create a web method, which receives the message and send it to JMS Topic
- Java Receiver - Create a Java Class and it can wait for the message asynchronously.
subscriber.setMessageListener(messageListerner);
connection.start();
Points of Interest
This application shows how we can receive messages from JMS to .NET Client, with out using any bridging technology, which is not only expensive but a big overhead. I am not a very good writer, so I hope everything will be understood by the architecture diagrams and code :)
History
01-14-2005: