views:

34

answers:

2

Hi, Recently I got asked to write a java application for my company. I'm a seasoned .Net developer so this is all new ground to me.

My task is to produce an invoicing application that has several high level tasks such as:

  • Build single invoice
  • Build all invoices

My company want to be able to call these tasks from a java console application - passing in relevant commands and parameters to invoke the tasks. They also want to be able to invoke the same code from an ASP.NET application.

Therefore my first thought was to use Web Services in Java.

My question is: Can I use Web Services in Java from both a Java Console Application and from an ASP.NET application? Or perhaps are there better alternatives.

Any pointers to get me researching in the right direction would be appreciated.

Thanks.

+1  A: 

"My company want to be able to call these tasks from a java console application - passing in relevant commands and parameters to call the tasks. They also want to be able to call the same code from an ASP.NET application."

I'm not sure exactly what you are asking, but I think the simple answer is to ensure that your application has an entry point method so that it can be run as a command line applications. You need a class with a method that looks like this:

package foo.bar;

public class Bazz {

    ...

    public static void main(String[] arguments) {
        // parse the arguments and run the application
        ...
    }
}

The signature of the main method is critical:

  • it must be public static,
  • it must have the name main,
  • it must tack a single String[] argument and,
  • it must have a void return type.

This command can then be run from the command line as follows:

java -cp <YOUR_CLASS_PATH> foo.bar.Baz arg1 arg2 ...

This can also be done by another application written in Java, and (I imagine) from ASP.NET as well.

Stephen C
A: 

The simple answer is - yes. Java has libraries for defining Web Services and deploying them, and both Java and .NET have utilities for generating Web Service clients. That's not to say it will be easy though!

If I was you, I would instead investigate creating a REST service using a JAX-RS implementation (my favourite is RestEASY). This will allow you to create a 'web service' without SOAP, i.e. http://server/invoices/1 might return

<invoice>
 <items>
  <item>apple</item>
  <item>banana</item>
 <items>
 <customer>robert</customer>
 <amount>5.00</amount>
</invoice>

Which it then should be easy to interpret in any language. Either way it will be a steep learning curve though. The main difference between Java and .NET is that while a lot of functionality is built in to .NET, in Java it's spread across the ecosystem, which is good because it provides variety, however it can take a bit longer to locate functionality.

Robert Wilson