Click here to Skip to main content
15,879,535 members
Articles / Web Development / Apache
Article

Consuming a .NET Web Service with Apache AXIS

Rate me:
Please Sign up or sign in to vote.
3.93/5 (22 votes)
15 Apr 2004Apache1 min read 275.1K   997   28   60
Consuming a .NET Web Service with Apache AXIS.

Introduction

In this article, I will present an example on how to develop a typical HelloWorld Web Service with .NET on IIS, and how to consume that service with Apache AXIS in Java. Apache AXIS is SOAP implementation provided by Apache. AXIS SOAP implementation is available in two languages, C++ and Java. In this article, I will use the Java implementation of AXIS SOAP. Apache AXIS can be downloaded from here.

HelloWorld.asmx file is a simple text file in C#. The class HelloWorld just extends with the class WebService and implements a method SayHelloWorld(). To make this method a web method, it is given the attributed [WebMethod]. IIS simply takes care of generating the SOAP message and the WSDL file for the client.

Web Service on IIS in .asmx file

C#
<%@ WebService Language="C#" Class="HelloWorld" %>
using System;
using System.Web.Services;
public class HelloWorld : WebService 
{
     [WebMethod] public String SayHelloWorld() 
     {
          return "Hello World";
     }
}

To consume this Web Service with AXIS, WSDL file for the HelloWorld Web Service needs to be downloaded.

Now, to consume this Web Service, Apache AXIS provides a tool WSDL2Java to convert WSDL specification file to Java code. This tool generates the four Java classes, and that will take care of processing XML and SOAP messaging, and makes the use of Web Service as simple as calling an object on a local machine.

> java org.apache.axis.wsdl.WSDL2Java <A href="http://localhost/HelloWorld.asmx?WSDL">http://localhost/HelloWorld.asmx?WSDL</A>

The above tool will generate the following four class files which can be used to access that Web Service.

  • HelloWorld.java
  • HelloWorldLocator.java
  • HelloWorldSoap.java
  • HelloWorldSoapStub.java

This is how the client program looks like:

JavaScript
package org.tempuri;
public class Client
{
      public static void main(String [] args)
      {
            try
            {  
                  HelloWorldLocator loc = new HelloWorldLocator();
                  HelloWorldSoap port = loc.getHelloWorldSoap();
                  System.out.println(port.sayHelloWorld());
            }
            catch(Exception e)
            {System.out.println(e.getMessage());}
      }
}

Before coming across Apache AXIS, my reaction to developing and consuming Web Service in Java was that it was a lot of pain. But with Apache AXIS, developing and consuming Web Service is as simple as in .NET platform.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Web Developer
United States United States
My name is Fahad Azeem. I am interested in distributed software development. Currently I am working for a software consulting company in Chicago which developes software in .NET platform.

My Blog: http://fahadaz.blogspot.com

Comments and Discussions

 
GeneralSoap Fault : Server unable to process request --&gt; The request must contain wsa:To header Pin
santtarius28-Sep-05 19:55
santtarius28-Sep-05 19:55 
Generaljava2wsdl Pin
jasonchewy27-Jun-05 4:06
jasonchewy27-Jun-05 4:06 
GeneralRe: java2wsdl Pin
jasonchewy27-Jun-05 4:22
jasonchewy27-Jun-05 4:22 
GeneralRe: java2wsdl Pin
Fahad Azeem28-Jun-05 16:04
Fahad Azeem28-Jun-05 16:04 
GeneralThanks! Pin
homerbush18-May-05 18:41
homerbush18-May-05 18:41 
GeneralRe: Thanks! Pin
Fahad Azeem20-May-05 17:27
Fahad Azeem20-May-05 17:27 
GeneralRe: Questions Pin
1sttiger4-Oct-05 13:49
1sttiger4-Oct-05 13:49 
GeneralRe: Questions Pin
1sttiger7-Oct-05 6:00
1sttiger7-Oct-05 6:00 
Generalconsuming AXIS ws with C# Pin
Anonymous24-Jan-05 12:07
Anonymous24-Jan-05 12:07 
GeneralRe: consuming AXIS ws with C# Pin
Fahad Azeem25-Jan-05 3:40
Fahad Azeem25-Jan-05 3:40 

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.