• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

invoking a Axis2/Soap webservice

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
kalyani goli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic