Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Non JSP client for Web Service

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cany anybody point me to an article, or source code that shows an example of a client created to invoke a web service.

I created a web service using RAD 6.0. It gernerated corresponding wsdl etc. RAD can also create a client project for you that uses a JSP (Test.jsp) to test the service code.

However, I would like to know how I can write clinet code myself, instead of relying on the client code that can be generated by RAD.

I would like to write client code that will be invoked from a non web app. As such, I do not want the client code to be JSP or Servlet based.

Any help with example, or pointing out any article will be helpful.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sam Gehouse
Other than Web Client (JSP) created by the RAD we can write the normal Standalone java class (main method) or we can write the EJB client

fine the example client below.

package com.ibm.Client;

import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;


public class Client {

// Creates new HelloWorldClient
public Client() {
}

public static void main (String args[]) {
try {
// EndPoint URL for the SparePartPrice web service.
String endpointURL =
"http://localhost:9080/JaxRPCExamples/services/HelloWorld";
// Method Name to invoke for the SparePartPrice web service
String methodName = "getMessage";
// Create the Service call
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpointURL));
call.setOperationName(new QName("getMessage",methodName));
call.addParameter("name",XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);

Object[] params = new Object[] {"INDIA"};

//Invoke the SparePartPrice web service
String response= (String) call.invoke(params);
//Print out the result
System.out.println("Message is "+response);
}
catch (Exception e) {
System.out.println(e.toString());
}
}
}
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be aware that this example uses the obsolete JAX-RPC API. You can find a client that uses the SAAJ API (which is still current) here.
 
catch it before it slithers away! Oh wait, it's a tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic