jQuery in Action, 2nd edition
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes STUB, Dynamic Proxy, DII Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "STUB, Dynamic Proxy, DII" Watch "STUB, Dynamic Proxy, DII" New topic

STUB, Dynamic Proxy, DII

Andy Smith
Ranch Hand

Joined: Sep 28, 2003
Posts: 239
What is the difference between STUB, Dynamic Proxy and DII??, Can anyone exaplein indeatil the advantages/ diadvantages with respect to each other.?

Share Knowledge to gain it.
SCJP 2, SCWCD 2, SCDJWS, IBM 141 (In Progress), IBM 486 (Next)
Worawisut P.

Joined: Jul 29, 2002
Posts: 3
In a nutshell speaking ,the difference between Dynamic Proxy and Generated Stub is the implementation of Remote Interface,since the Remote Interface of Dynamic Proxy is generated dynamically at runtime.
(Remember that Generated Stub is generated during deployment time by JAX-RPC compiler ,which generates both remote interface (called Endpoint Interface) and stub ,which implements corresponding remote interface.)
The Stub of Dynamic Proxy is generated while "javax.xml.rpc.Service.getPort()" was executed.
DII (It's acronyms for "Dynamic Invocation Interface") can invoke web service operation without using remote interface or stub.
Because you can directly get a reference to the web service by using "javax.xml.rpc.Service.createCall()".
(The things you should know are either "port" name or "operation" name.)
QName portName = new QName("http://blablabla","Foo");
Call call=createCall(portName);
Object[] inputs = new Object(1);
String name=(String)call.invoke(inputs);

Worawisut P.
[ May 10, 2004: Message edited by: Worawisut P. ]
[ May 10, 2004: Message edited by: Worawisut P. ]
Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
There is a pretty comprehensive comparison table in WebServices BluePrints Chapter 4. Section (Page 141). That should answer many questions.

Unnikrishnan Nair
Ranch Hand

Joined: Mar 12, 2003
Posts: 42
This is a late add, feel free to add any updates.....

Web Services can be invoked in three different ways

1. Using Generated Stub
2. Using Dynamic Proxies
3. Using Dynamic Invocation Interface (DII)

In Generated Stub, client depends on generated interfaces of service (last block in WSDL) and portType (business definition), and their implemented stub & proxy classes. The code need to create the specific service from generated stub, and get its specific portType object from it. Then call business method

In Dynamic Invocation Interface, client does not care about the generated service stub, but creates the framework “Service” object by passing the actual service name. From the framework Service object, the client gets the generated portType object by passing the portType name. Then call the business method on the portType object

In Dynamic Invocation Interface (DII), the client does not use any generated class. It creates a Service object, and creates a Call object out of it. To the call object, client sets the name of Service, name of portType and invoke it by passing an Object array of parameters.

In short, Generated Stub uses all generated classes
Dynamic Proxy uses only generated portType
DII does not use any generated classes

Example code below (using Axis)

package com.test.webmain;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.naming.NamingException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.client.ServiceFactory;

import com.test.HelloTest;
import com.test.HelloTestService;
import com.test.HelloTestServiceLocator;

public class WebMain {

* @param args
* @throws ServiceException
* @throws MalformedURLException
* @throws RemoteException
* @throws NamingException
public static void main(String[] args) throws ServiceException,
MalformedURLException, RemoteException, NamingException {

//Accessing through stub
HelloTestService service1 = new HelloTestServiceLocator();
HelloTest test = service1.getHelloTest();

//Dynamic Proxy
try {

ServiceFactory serviceFactory = (ServiceFactory) ServiceFactory.newInstance();
System.out.println("Got the service factory");

String endpoint = "http://localhost:8080/TestWS/services/HelloTest?wsdl";
URL wsdlURL = new URL(endpoint);

Service service = (Service) serviceFactory.createService(
wsdlURL, new QName("http://test.com", "HelloTestService"));
System.out.println("Got the service: " + service);

HelloTest test1 = (HelloTest) service.getPort(
new QName("http://test.com", "HelloTest"), HelloTest.class);

System.out.println("Sent 'Unni!', got '" + test1.sayHello("Unni") + "'");
} catch (Exception e) {

//Dynamic Invocation Interface
try {
String endpoint = "http://localhost:8080/TestWS/services/HelloTest";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("sayHello"));
String ret = (String) call.invoke(new Object[] { "Unni" });
System.out.println("Sent 'Unni!', got '" + ret + "'");
} catch (Exception e) {

SCJP, SCWCD, SCBCD, SCDJWS, SCSNI, SCEA 5, PMP, Six Sigma Green Belt, Certified Scrum Master
I agree. Here's the link: http://aspose.com/file-tools
subject: STUB, Dynamic Proxy, DII