Click here to Skip to main content
12,072,540 members (56,405 online)
Click here to Skip to main content
Add your own
alternative version

Stats

202.4K views
934 downloads
28 bookmarked
Posted

Consuming a .NET Web Service with Apache AXIS

, 15 Apr 2004 Apache
Rate this:
Please Sign up or sign in to vote.
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

<%@ 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:

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

Share

About the Author

Fahad Azeem
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

You may also be interested in...

Comments and Discussions

 
GeneralRe: Problem with axis.jar Pin
sonal_hotmail29-May-08 2:03
membersonal_hotmail29-May-08 2:03 
Generalthe other way around Pin
oxygen_fiend18-May-06 19:28
memberoxygen_fiend18-May-06 19:28 
GeneralRe: the other way around Pin
Fahad Azeem19-May-06 4:39
memberFahad Azeem19-May-06 4:39 
GeneralRe: the other way around Pin
oxygen_fiend19-May-06 15:03
memberoxygen_fiend19-May-06 15:03 
GeneralRe: the other way around Pin
Fahad Azeem19-May-06 17:34
memberFahad Azeem19-May-06 17:34 
GeneralRe: the other way around Pin
oxygen_fiend19-May-06 17:47
memberoxygen_fiend19-May-06 17:47 
GeneralRe: the other way around Pin
EdwinY7-Aug-08 0:43
memberEdwinY7-Aug-08 0:43 
QuestionError thrown parsing asmx page? Pin
Jesse W. Reno23-Feb-06 13:54
memberJesse W. Reno23-Feb-06 13:54 
Hi,

Thanks for the how-to, after a not of QName learning-about and struggle I think I am getting somewhere, however now I am getting this error.

Error javax.xml.rpc.ServiceException: Error processing WSDL document:
org.xml.sax.SAXException: Fatal Error: URI=http://localhost/TestApp/TestService.asmx Line=105: Expected "

" to terminate element starting on line 103.


And when I look at the source for my generated and I do indeed have a

tag starting there. Totally confused about why this is happening. There are planty of other unclosed

tags in this html?

This is the HTML generated by ASP.NET right - I can't even change it if I want.

Aaargh.

Any help would be much appreaciated

_______________________
bob

AnswerRe: Error thrown parsing asmx page? Pin
Fahad Azeem24-Feb-06 15:20
memberFahad Azeem24-Feb-06 15:20 
GeneralRe: Error thrown parsing asmx page? Pin
aaazzzdddd17-Sep-07 3:37
memberaaazzzdddd17-Sep-07 3:37 
GeneralGetting this error Pin
Muhammad Irfan Azam21-Feb-06 23:57
memberMuhammad Irfan Azam21-Feb-06 23:57 
GeneralRe: Getting this error Pin
Fahad Azeem24-Feb-06 15:19
memberFahad Azeem24-Feb-06 15:19 
GeneralThanks for the information Pin
WillemM18-Jan-06 9:30
memberWillemM18-Jan-06 9:30 
GeneralRe: Thanks for the information Pin
Fahad Azeem20-Jan-06 8:43
memberFahad Azeem20-Jan-06 8:43 
Generalwsdl2java Pin
Ranganaths18-Jan-06 8:01
memberRanganaths18-Jan-06 8:01 
GeneralRe: wsdl2java Pin
Fahad Azeem20-Jan-06 8:41
memberFahad Azeem20-Jan-06 8:41 
QuestionConnections on server not closed Pin
pschrot9-Dec-05 3:32
memberpschrot9-Dec-05 3:32 
QuestionSSL connection with Apache Axis Pin
wouter devers19-Nov-05 5:53
memberwouter devers19-Nov-05 5:53 
AnswerRe: SSL connection with Apache Axis Pin
Fahad Azeem21-Nov-05 10:38
memberFahad Azeem21-Nov-05 10:38 
QuestionHow to Set User Credential in Apache AXIS Pin
1sttiger7-Oct-05 7:07
member1sttiger7-Oct-05 7:07 
AnswerRe: How to Set User Credential in Apache AXIS Pin
Fahad Azeem7-Oct-05 7:57
memberFahad Azeem7-Oct-05 7:57 
GeneralSoap Fault : Server unable to process request --&gt; The request must contain wsa:To header Pin
santtarius28-Sep-05 20:56
membersanttarius28-Sep-05 20:56 
GeneralRe: Soap Fault : Server unable to process request --&gt; The request must contain wsa:To header Pin
Fahad Azeem29-Sep-05 5:14
memberFahad Azeem29-Sep-05 5:14 
GeneralRe: Soap Fault : Server unable to process request --&gt; The request must contain wsa:To header Pin
santtarius29-Sep-05 22:44
membersanttarius29-Sep-05 22:44 
GeneralSoap Fault : Server unable to process request --&gt; The request must contain wsa:To header Pin
santtarius28-Sep-05 20:55
membersanttarius28-Sep-05 20:55 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 16 Apr 2004
Article Copyright 2004 by Fahad Azeem
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid