aspose file tools*
The moose likes Web Services and the fly likes invoking a Axis2/Soap webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "invoking a Axis2/Soap webservice" Watch "invoking a Axis2/Soap webservice" New topic
Author

invoking a Axis2/Soap webservice

kalyani goli
Greenhorn

Joined: Nov 26, 2008
Posts: 4
I need some technical help in webservices.
I should invoke a Axis2/SOAP WS-I compliant Web Service from a web application.

I tried to use stubs, but it is not working.
When hitting the end point url, I should pass object (complex datatype in wsdl file) as parameter. Could any one help me where to start?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
Welcome to JavaRanch.
I tried to use stubs, but it is not working.

What does this mean? Where did these stubs come from, how were you using them, and what exactly was the result?


Ping & DNS - my free Android networking tools app
kalyani goli
Greenhorn

Joined: Nov 26, 2008
Posts: 4
when I search in the net, i am getting the following example. but i need to pass an object as parameter.
Can any one please help me How to pass an object to call.addparameter() mehtod?

It is defined as follows in wsdl file.
<complexType name="xyzpPacket">

<sequence>
<element name="userName" nillable="true" type="xsd:string"/>
<element name="domain" nillable="true" type="xsd:string"/>
<element name="domainAuth" type="xsd:boolean"/>
<element name="userId" nillable="true" type="xsd:long"/>
....
</sequence>
</complexType>


package samples.userguide.example2;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;

import javax.xml.rpc.ParameterMode;

public class CalcClient {
public static void main(String [] args) throws Exception {
Options options = new Options(args);

String endpoint = "http://localhost:" + options.getPort() +
"/axis/Calculator.jws";

// Do argument checking
args = options.getRemainingArgs();

if (args == null || args.length != 3) {
System.err.println("Usage: CalcClient <add|subtract arg1 arg2");
return;
}

String method = args[0];
if (!(method.equals("add") || method.equals("subtract"))) {
System.err.println("Usage: CalcClient <add|subtract arg1 arg2");
return;
}

// Make the call
Integer i1 = new Integer(args[1]);
Integer i2 = new Integer(args[2]);

Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName( method );
call.addParameter("op1", XMLType.XSD_INT, ParameterMode.PARAM_MODE_IN);
call.addParameter("op2", XMLType.XSD_INT, ParameterMode.PARAM_MODE_IN);
call.setReturnType(XMLType.XSD_INT);

Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });

System.out.println("Got result : " + ret);
}
}
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by kalyani goli:
when I search in the net, i am getting the following example.


Your code example refers to Axis 1.x, not Axis2.

To generate the Java artifacts from the WSDL use WSDL2Java.

Choosing a Client Generation Method
Quickstart Guide: Generating a Client using ADB
WSDL2Java Reference
[ November 26, 2008: Message edited by: Peer Reynders ]
kalyani goli
Greenhorn

Joined: Nov 26, 2008
Posts: 4
thanks for the reply. Should I use the same method, even if I am calling it from a web application.

Thanks in advance

Kalyani
kalyani goli
Greenhorn

Joined: Nov 26, 2008
Posts: 4
Thanks for the reply
when should I use the AXIOMClient class using AXIOM.

So, I need to have stubs to access the web service. I can't access just by mentioning end point URL and passing parameters as shown in the example.

Could you please elaborate on this.

Thanks in advance,
Kalyani
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by kalyani goli:
Should I use the same method, even if I am calling it from a web application.


You should be able to use the stub in a web application. However, as you are doing this for the first time, I'd suggest attempting it as a command line client first, so that you can iron out your own understanding of how to use the generated artifacts first.


when should I use the AXIOMClient class using AXIOM

You shouldn't. AXIOM is intended for the exchange of raw XML payloads - i.e. you would be working with raw XML represented in AXIs2 Object Model (AXIOM).
Writing Web Service Clients Using Axis2's Primary APIs


You have a WSDL - so you should be using WSDL2Java to generate a stub. The stub will make Java representations of the XML available.
Writing a Web Service Client

By default WSDL2Java uses Axis2 Data Binding (ADB) (So this might interest you).

If you don't mind the extra work you could try data binding with JiBX which lets you configure mappings between your own objects and the XML required by the WSDL.


I can't access just by mentioning end point URL and passing parameters as shown in the example.

Not unless you want to manually derive the formal structure of the supported SOAP requests and responses from the WSDL that you were handed and then programmatically build the requests from scratch, to later pry the result out of the SOAP response with SAAJ (or AXIOM).

The code example you showed accessed a RPC/encoded web service - Axis2 doesn't even support the RPC/encoded messaging mode anymore; it caused nothing but trouble (they weren't compliant with the WS-I Basic Profile).

With Axis2 org.apache.axis2.rpc.client.RPCServiceClient fills a similar niche. However it isn't interoperable and will not generate the requests that you need.
[ November 26, 2008: Message edited by: Peer Reynders ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invoking a Axis2/Soap webservice