Consume .NET web-service in Java.

November 13, 2006

Make the necessary changes to the web-service project in the web.config file to make it accessible to the HTTP GET & POST calls.

This is a simple Java program illustrating how you can consume the .NET web-service in Java program.


public class WebService
public static void main(String[] args) throws Exception
URL webserviceURL = new URL(“http://localhost/MyServices/WebService1.asmx/Service1”);
URLConnection webserviceConnection = webserviceURL.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(webserviceConnection.getInputStream()));
String inputLine;

while ((inputLine = in.readLine()) != null)


In response your get the proper XML data. So, now you need to parse the XML so as to get the essential data from it. As you can see that consuming your .NET web-service in Java is not a tricky thing 🙂



One Response to “Consume .NET web-service in Java.”

  1. Anand Says:

    i tried this example.
    but its showing following error


    C:\javaprograms>java webService
    Exception in thread “main” java.lang.UnsupportedClassVersionError: webService (U
    nsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at Source)
    at Source)
    at$100(Unknown Source)
    at$ Source)
    at Method)
    at Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: