• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling Java Code from C#

 
Ranch Hand
Posts: 160
IntelliJ IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys

I'm faced with an interesting problem.

I need to call a web service from C#. The server (which will respond to the web service call) is written in Java. Up to know, we've only ever used Java-based clients. The web service takes a String as parameter. This String contains representations of a number of POJOs, encoded in our own format. The Java libraries containing these POJOs are referenced on both the server and client Java applications.

Short of duplicating all the POJOs and the encoder in C#, can you think of a way to handle this? I'm leaning towards trying to find a solution that will allow me to call the Java code used in our existing Java-based clients from C#. I think that I'll be able to write a Java method that takes XML input and a Java class name as input, instantiate the specified class using reflection, call the web service and return an XML String containing the web service call result to the calling C# code. Any thoughts on this approach?

Thanks for your input.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a past project, I had to call Java code from C# and vice versa. We used a library called JuggerNET to do that, but I wouldn't recommend doing that. It's cumbersome, there are some pitfalls and the performance is not very good and it just feels like a hack, and not something that works seamlessly. I'd rather just duplicate the POJOs in C# than using this again.

You say that the format that the data is in is something that you invented yourself, but later you're also talking about XML. If it is in XML, then you can get a long way using JAXB and the xjc tool included with the JDK, which can generate your Java beans from an XML schema. I don't know if something similar exists for C#, but it would be nice if you'd only have to specify the data structures once in for example an XSD, from which you could generate the Java and C# POJOs.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jesper

Thank you for your response.

Jesper de Jong wrote:
You say that the format that the data is in is something that you invented yourself, but later you're also talking about XML.


What I meant here is that I could write something in Java to execute the web service, convert the result from our own format to plain 'ol XML and return the XML to the calling C# code.

We've decided to expand our server web service to accept input and return output in plain XML, in addition to our format. Whenever someone wants to chat to our server from C# (or any other language, for that matter) they can give us plain XML, and if it's valid, we'll process the request and return plain XML. Anything beyond that is not our concern.

Cheers,
Riaan
 
reply
    Bookmark Topic Watch Topic
  • New Topic