Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / Java / Java SE
Article

Using C#, Java Webservices and JMS together

,
Rate me:
Please Sign up or sign in to vote.
3.80/5 (10 votes)
31 Mar 2006CPOL2 min read 127.9K   2.4K   57   19
Bridging the gap between Java and C#, JMS specific message have been send to C# client using web services.

Image 1

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

  1. Asynchronous DOTNET Web services
  2.  DOTNET Delegates
  3. Java Webservices - AXIS 
  4. Java Messaging Service (JMS)
  5. 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

  1. Java Web service.

    Open the project in JbuilderX and run the server with the configuration "Start Web Services Server"
  2. .NET Client

    Update the Web Reference
    Run the application using Visual Studio .NET 2003
  3. 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

Image 2

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.  

C#
 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

C#
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.
  1. .NET application as a sender -  Create a web method, which receives the message and send it to JMS Topic
  2. Java Receiver - Create a Java Class and it can wait for the message asynchronously.
    subscriber.setMessageListener(messageListerner);
    connection.start();
    // No need to do this as the message will be received in messageListerner</CODE>
    //subscriber.receive();

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:

  • Original article

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Architect Catalisse
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 4 Pin
Md. Marufuzzaman2-Jun-12 2:39
professionalMd. Marufuzzaman2-Jun-12 2:39 
QuestionHow to run the web service in JBuilder Pin
eyadalagha12-Nov-07 10:33
eyadalagha12-Nov-07 10:33 
GeneralInteresting approach... Pin
michael_rost11-Jun-07 9:20
michael_rost11-Jun-07 9:20 
NewsTechnology Name Pin
Armoghan Asif15-May-07 3:11
Armoghan Asif15-May-07 3:11 
Questionhow web service communicate with Alchemi Cross Platform Manager Pin
punit singh9-May-07 23:21
punit singh9-May-07 23:21 
AnswerRe: how web service communicate with Alchemi Cross Platform Manager Pin
Armoghan Asif10-May-07 22:20
Armoghan Asif10-May-07 22:20 
I think you have posted on wrong place.. This article has nothing to do with Alchmi
Generalcsil project challenge Pin
fawce12-Jul-06 10:08
fawce12-Jul-06 10:08 
GeneralDo things simple! Pin
Vitaly Shelest22-Jun-06 3:11
Vitaly Shelest22-Jun-06 3:11 
GeneralRe: Do things simple! Pin
Armoghan Asif23-Jun-06 21:06
Armoghan Asif23-Jun-06 21:06 
QuestionCan not download! Pin
Pham Ngoc Quyen4-Mar-05 19:26
Pham Ngoc Quyen4-Mar-05 19:26 
AnswerRe: Can not download! Pin
Armoghan Asif6-Mar-05 22:06
Armoghan Asif6-Mar-05 22:06 
GeneralRe: Can not download! Pin
Prasad Khandekar18-Jul-05 20:46
professionalPrasad Khandekar18-Jul-05 20:46 
GeneralRe: Can not download! Pin
Armoghan Asif20-Jul-05 19:07
Armoghan Asif20-Jul-05 19:07 
GeneralRe: Can not download! Pin
Prasad Khandekar21-Jul-05 4:51
professionalPrasad Khandekar21-Jul-05 4:51 
GeneralRe: Can not download! Pin
EyalSch213-Mar-06 8:43
EyalSch213-Mar-06 8:43 
General...and easy to generalize! Pin
David Dossot24-Jan-05 4:15
David Dossot24-Jan-05 4:15 
GeneralRe: ...but there is a better approach for JBoss users! Pin
David Dossot10-Jan-06 1:46
David Dossot10-Jan-06 1:46 
GeneralInteresting approach... Pin
David Dossot23-Jan-05 21:42
David Dossot23-Jan-05 21:42 
GeneralRe: Interesting approach... Pin
Armoghan Asif24-Jan-05 17:28
Armoghan Asif24-Jan-05 17:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.