Click here to Skip to main content
Licence Apache
First Posted 15 Apr 2004
Views 173,597
Bookmarked 28 times

Consuming a .NET Web Service with Apache AXIS

By | 15 Apr 2004 | Article
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

About the Author

Fahad Azeem

Web Developer

United States United States

Member

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralProblem calling update method of the webservice PinmemberPradeepchy22:24 12 Nov '09  
GeneralGetting PKIX error while trying to connect a .net webservice by java client PinmemberMember 44927853:49 26 Aug '09  
GeneralError while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE Pinmembermoodbidri23:21 1 Jul '09  
GeneralRe: Error while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE Pinmembermoodbidri23:59 1 Jul '09  
GeneralRe: Error while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE Pinmembermoodbidri23:59 1 Jul '09  
GeneralRe: Error while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE PinmemberFahad Azeem5:31 2 Jul '09  
Questionwsdl2java error PinmemberPrince_Taj20:30 22 May '07  
AnswerRe: wsdl2java error Pinmemberactivea_0:59 12 Jun '07  
QuestionConsuming a java web service???? Pinmemberbuzz101-zn6:34 18 May '07  
GeneralProblem writing c# web client Pinmemberguilho11:22 11 Apr '07  
Hi all.
I'm having a problem while writing a web service client to access a web service installed on a remote computer. The web service is the "SRW" ( Search and Retrieve Web Service ).
I've already wrote the client code in Java language (helped by WSDL2JAVA tool with Eclipse), and it works fine. Now i need to write it in C# in another computer, to access SRW on the other one.
I'm using Visual Studio 2005.
 
My problem is, while adding the web reference to my project in VS, Vs doesn't recogzine all the classes of the web-service, and i think that's because the Web Service has some classes that are extended by apache axis, in java. The WSDl was generated by apache axis i think...
Visual Studio, doesn't have any means to interacting with apache axis on the client side ?
 
So, resuming i need to access a web service in java, by a C# web client.
Do you know any way of interacting Visual sTUDIO with the apache axis ? I'm saying this because i think the problem comes from there...
Here's an example of a class SRWSampleServiceLocator in Java, generated by WSDL2JAVA:
 
#################################
public class SRWSampleServiceLocator extends org.apache.axis.client.Service implements gov.loc.www.zing.srw.srw_sample_service.SRWSampleService {
 
// Use to get a proxy class for SRW
private final java.lang.String SRW_address = "http://insertserver/inserturl/";
 
public java.lang.String getSRWAddress() {
return SRW_address;
}
################################
 
Hope you can help.
best regards
Guilherme
GeneralRe: Problem writing c# web client PinmemberFahad Azeem5:27 12 Apr '07  
GeneralRe: Problem writing c# web client Pinmemberguilho5:19 13 Apr '07  
GeneralRe: Problem writing c# web client PinmemberFahad Azeem11:55 16 Apr '07  
GeneralError consuming the service PinmemberRavi Gurbaxani2:46 17 Jan '07  
GeneralRe: Error consuming the service PinmemberFahad Azeem15:31 17 Jan '07  
GeneralRe: Error consuming the service PinmemberRavi Gurbaxani17:48 17 Jan '07  
QuestionWeb servers in jbuilder Pinmembermesbih7:39 6 Jan '07  
AnswerRe: Web servers in jbuilder PinmemberFahad Azeem11:25 8 Jan '07  
Newshttp://casino-slots.ceroline.info/ Pinsusshttp://casino-slots.ceroline.info/2:25 4 Dec '07  
Generalhoe to pass user credentials Pinmembera_s_a19:42 23 May '06  
GeneralRe: how to pass user credentials PinmemberFahad Azeem4:00 25 May '06  
GeneralProblem with axis.jar PinmemberGowtam Kamath19:17 22 May '06  
GeneralRe: Problem with axis.jar PinmemberFahad Azeem11:59 23 May '06  
GeneralRe: Problem with axis.jar PinmemberGowtam Kamath19:41 23 May '06  
GeneralRe: Problem with axis.jar PinmemberRameshtcs17:15 18 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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