Click here to Skip to main content
15,883,907 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.3K   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

 
GeneralProblem writing c# web client Pin
guilho11-Apr-07 11:22
guilho11-Apr-07 11:22 
GeneralRe: Problem writing c# web client Pin
Fahad Azeem12-Apr-07 5:27
Fahad Azeem12-Apr-07 5:27 
GeneralRe: Problem writing c# web client Pin
guilho13-Apr-07 5:19
guilho13-Apr-07 5:19 
GeneralRe: Problem writing c# web client Pin
Fahad Azeem16-Apr-07 11:55
Fahad Azeem16-Apr-07 11:55 
GeneralError consuming the service Pin
Ravi Gurbaxani17-Jan-07 2:46
Ravi Gurbaxani17-Jan-07 2:46 
GeneralRe: Error consuming the service Pin
Fahad Azeem17-Jan-07 15:31
Fahad Azeem17-Jan-07 15:31 
GeneralRe: Error consuming the service Pin
Ravi Gurbaxani17-Jan-07 17:48
Ravi Gurbaxani17-Jan-07 17:48 
QuestionWeb servers in jbuilder Pin
mesbih6-Jan-07 7:39
mesbih6-Jan-07 7:39 
AnswerRe: Web servers in jbuilder Pin
Fahad Azeem8-Jan-07 11:25
Fahad Azeem8-Jan-07 11:25 
Newshttp://casino-slots.ceroline.info/ Pin
http://casino-slots.ceroline.info/4-Dec-07 2:25
susshttp://casino-slots.ceroline.info/4-Dec-07 2:25 
Generalhoe to pass user credentials Pin
a_s_a23-May-06 19:42
a_s_a23-May-06 19:42 
GeneralRe: how to pass user credentials Pin
Fahad Azeem25-May-06 4:00
Fahad Azeem25-May-06 4:00 
GeneralProblem with axis.jar Pin
Gowtam Kamath22-May-06 19:17
Gowtam Kamath22-May-06 19:17 
GeneralRe: Problem with axis.jar Pin
Fahad Azeem23-May-06 11:59
Fahad Azeem23-May-06 11:59 
GeneralRe: Problem with axis.jar Pin
Gowtam Kamath23-May-06 19:41
Gowtam Kamath23-May-06 19:41 
GeneralRe: Problem with axis.jar Pin
Rameshtcs18-Jan-07 17:15
Rameshtcs18-Jan-07 17:15 
GeneralRe: Problem with axis.jar Pin
sonal_hotmail29-May-08 1:03
sonal_hotmail29-May-08 1:03 
Generalthe other way around Pin
oxygen_fiend18-May-06 18:28
oxygen_fiend18-May-06 18:28 
GeneralRe: the other way around Pin
Fahad Azeem19-May-06 3:39
Fahad Azeem19-May-06 3:39 
GeneralRe: the other way around Pin
oxygen_fiend19-May-06 14:03
oxygen_fiend19-May-06 14:03 
GeneralRe: the other way around Pin
Fahad Azeem19-May-06 16:34
Fahad Azeem19-May-06 16:34 
GeneralRe: the other way around Pin
oxygen_fiend19-May-06 16:47
oxygen_fiend19-May-06 16:47 
GeneralRe: the other way around Pin
EdwinY6-Aug-08 23:43
EdwinY6-Aug-08 23:43 
QuestionError thrown parsing asmx page? Pin
Jesse W. Reno23-Feb-06 12:54
Jesse W. Reno23-Feb-06 12:54 
AnswerRe: Error thrown parsing asmx page? Pin
Fahad Azeem24-Feb-06 14:20
Fahad Azeem24-Feb-06 14:20 

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.