Click here to Skip to main content
15,887,676 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.6K   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

 
QuestionIs it me or does this just convert a C# web service to a Java one? Pin
riahc32-Jun-12 21:19
riahc32-Jun-12 21:19 
GeneralProblem calling update method of the webservice Pin
Pradeepchy12-Nov-09 22:24
Pradeepchy12-Nov-09 22:24 
GeneralGetting PKIX error while trying to connect a .net webservice by java client Pin
Member 449278526-Aug-09 3:49
Member 449278526-Aug-09 3:49 
HI Fahad,

I have to consume a .net web service over ssl in java.
When i open the wsdl in browser i have to provide some credentials to get it opened.
Initially when I was trying to create client stub via wsdl2java using actual uri (i.e. https:/....) i was getting following error-----

org.apache.axis2.AxisFault: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

So I copied the wsdl and schema into local machine changed the schemalocation in wsdl to local machine and created client stub.

Now when i fire a method call I am again getting same error.
I have read into some forums that I have to provide some certificate while making call like below.

System.setProperty("javax.net.ssl.trustStore", "keys/sec.jks"); System.setProperty("javax.net.ssl.trustStorePassword", "password"); System.setProperty("javax.net.ssl.trustStoreType","JKS");

but i am not very clear about this what keys and what password i have to provide. Regarding this Should I contact .net webservice team

Please help me out.
I am pasting the exact error below
***************************************************
org.apache.axis2.AxisFault: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:83)
at org.apache.axis2.transport.http.AxisRequestEntity.writeRequest(AxisRequestEntity.java:84)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.writeRequestBody(EntityEnclosingMethod.java:499)
at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2114)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:189)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:364)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:208)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at com.hp.globalops.hppws.DocLiteralServiceStub.checkUserExists(DocLiteralServiceStub.java:1343)
at com.hp.globalops.hppws.client.main(client.java:40)
Caused by: com.ctc.wstx.exc.WstxIOException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:313)
at org.apache.axiom.om.impl.MTOMXMLStreamWriter.flush(MTOMXMLStreamWriter.java:146)
at org.apache.axis2.databinding.utils.writer.MTOMAwareXMLSerializer.flush(MTOMAwareXMLSerializer.java:79)
at org.apache.axis2.databinding.ADBDataSource.serialize(ADBDataSource.java:94)
at org.apache.axiom.om.impl.llom.OMSourcedElementImpl.internalSerializeAndConsume(OMSourcedElementImpl.java:664)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:918)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerializeAndConsume(OMElementImpl.java:947)
at org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.serializeInternally(SOAPEnvelopeImpl.java:240)
at org.apache.axiom.soap.impl.llom.SOAPEnvelopeImpl.internalSerialize(SOAPEnvelopeImpl.java:228)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerializeAndConsume(OMElementImpl.java:947)
at org.apache.axiom.om.impl.llom.OMNodeImpl.serializeAndConsume(OMNodeImpl.java:471)
at org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMessageFormatter.java:79)
... 19 more
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1611)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1035)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:124)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:623)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at java.io.FilterOutputStream.flush(FilterOutputStream.java:123)
at org.apache.commons.httpclient.ChunkedOutputStream.flush(ChunkedOutputStream.java:191)
at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:99)
at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:214)
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:311)
... 30 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:285)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:191)
at sun.security.validator.Validator.validate(Validator.java:218)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1014)
... 44 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:280)
... 50 more
GeneralError while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE Pin
moodbidri1-Jul-09 23:21
moodbidri1-Jul-09 23:21 
GeneralRe: Error while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE Pin
moodbidri1-Jul-09 23:59
moodbidri1-Jul-09 23:59 
GeneralRe: Error while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE Pin
moodbidri1-Jul-09 23:59
moodbidri1-Jul-09 23:59 
GeneralRe: Error while invoking webmethod - java.net.UnknownHostException: USE_ADDRESS_RETURNED_BY_LOCATION_SERVICE Pin
Fahad Azeem2-Jul-09 5:31
Fahad Azeem2-Jul-09 5:31 
Questionwsdl2java error Pin
Prince_Taj22-May-07 20:30
Prince_Taj22-May-07 20:30 
AnswerRe: wsdl2java error Pin
activea_12-Jun-07 0:59
activea_12-Jun-07 0:59 
QuestionConsuming a java web service???? Pin
buzz101-zn18-May-07 6:34
buzz101-zn18-May-07 6:34 
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 

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.