Home > Products > JRun > Support > Web Services
Macromedia JRun Support Center - Web Services
Consuming a web service in JRun

You can create either proxy or dynamic clients that invoke web service operations.

A "proxy client" calls methods on a local proxy generated from a WSDL file for a specific web service. The proxy object handles interaction with the remote web service and you make simple method calls on the proxy.

You use the Axis WSDL2Java tool to generate proxies from WSDL documents. When you use proxy client, you don't need to deal with complex data types that the web service might use; WSDL2Java generates JavaBeans that correspond to the complex data types declared in a WSDL document.

A "dynamic client" is a JSP or Java class that invokes operations by calling the Axis client API directly. JRun provides a JSP custom tag library, the Web Services Tag Library, that acts as a wrapper to the Axis client API.

Using a proxy client
You can use the WSDL2Java tool to generate a Java-based web service proxy, even when the actual web service implementation is a non-Java component, such as a Microsoft .NET component. You run the WSDL2Java tool using a command in which you specify an output directory and a WSDL file:

wsdl2java -o output_directory localpath/your_file.wsdl

After generating proxy code, you can create a proxy client, such as a JSP, in which you do the following:

1 Instantiate a proxy factory and a proxy; for example:


proxy.SampleServiceService stubFactory =

new proxy.SampleServiceService();

proxy.Sample stub = stubFactory.getSampleService();


2 Call the proxy's method(s) and print the result to the page; for example:

<%= stub.getResult(3)%>

Using a JSP tag-based dynamic client
Using the JRun Web Services Tag Library, you can call a web service operation using just a couple of JSP custom tags when you know some basic things about the web service.

To use the invoke tag, you will need to know the following:

URL of the web service endpoint ( invoke url attribute)
XML namespace of the web service ( invoke namespace attribute)
Expected data type of the returned value ( invoke resultType attribute)
Name of the operation to invoke ( invoke operation attribute)
Name of the variable in which to store the operation result ( invoke result attribute)

Nested in the invoke tag are param tags in which you specify the names and values of the web service operation parameters.

The following is a simple fictional example:

<%@ taglib prefix="web" uri="webservicetag" %>

<% String str1="BRL";

String str2="USD";%>







<web:param name="fromCurr" value="<%=str1%>"/>

<web:param name="ToCurr" value="<%=str2%>"/>


<%= pageContext.getAttribute("myresult") %>

Using a JSP scriptlet-based dynamic client
Using a JSP scriptlet-based or object-based dynamic client is essentially the same except for the difference between scriptlet syntax and standard Java syntax.

For a scriptlet-based client, you typically do the following:

1 Import the required Axis classes.
2 Assign a variable for the endpoint URL, the destination for SOAP messages.
3 Instantiate Axis Service and Call objects; these objects store metadata about the service to invoke:
4 Set the web service endpoint URL.
5 Set the name of the web service operation (method) to be invoked.
6 Set the namespace to use in the body of SOAP messages.
7 Set the operation parameter name(s).
8 Set the return type.
9 Invoke the web service.
The following is a simple example:

%@page import="org.apache.axis.client.Call,


javax.xml.rpc.ParameterMode" %>

<% String endpoint =


Service service = new Service();

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



call.setProperty(Call.NAMESPACE, "");

call.addParameter("testParam", XMLType.XSD_STRING,

Call.PARAM_MODE_IN); call.setReturnType( XMLType.XSD_STRING );%>

<%=call.invoke(new Object[] {"Hello!"})%>

For more information about consuming web services in JRun, see JRun Programmer's Guide in the JRun 4 installation.

Submit feedback about this tutorial.

To Table of Contents Back to Previous document