Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Compilation of a Dynamic Proxy Client

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a question about the Dynamic Proxy Client which is extracted from the scjws guide of Mikalai Zaikin.

1/ How can I compile this java code because I don't have the com.example.HelloIF class when I write the client ?

2/ If the web service uses complex types in parameters, you don't have these complex types when you write this dynamic proxy client, how can I compile the java client code ?

Thanks.

Olivier

package com.example;

import java.net.URL;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;

public class HelloClient {
public static void main(String[] args) {
try {
String UrlString = "http://localhost:8080/ProxyHelloWorld.wsdl";
String nameSpaceUri = "http://sample.proxy.org/wsdl";
String serviceName = "HelloWorld"; // maps to service name in WSDL
String portName = "HelloIFPort"; // maps to port name in WSDL
URL helloWsdlUrl = new URL(UrlString);

ServiceFactory serviceFactory = ServiceFactory.newInstance();

// Create a Service object named helloService
Service helloService = serviceFactory.createService(helloWsdlUrl, new QName(nameSpaceUri, serviceName));

// Destination for service endpoint retrieval
QName qn = new QName(nameSpaceUri, portName);

// Create a proxy with type of interface 'com.example.HelloIF'
HelloIF myProxy = (HelloIF) helloService.getPort(qn, com.example.HelloIF.class);

System.out.println(myProxy.sayHello("Duke"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We need to use WSDL2Java Tools to generate service endpoint interface, complex parameters and return values.

----------------------------------------------------
Reference: Java Webservices Blue Prints Chapter 5.

5.3.4 WSDL-to-Java Type Mapping

Although not advisable, it is possible for a developer to work without the
benefit of a mapping tool, if none are available. However, without such mapping
tools the scope of the developer´┐Żs work greatly expands. For example, just to
compile the client code, the developer must understand the WSDL for a service
and generate by hand Java classes that match the parameter and return types
defined in the WSDL document or, in the case of a dynamic proxy, the client-side
representation of the service endpoint interface
. These classes must be set up properly
so that the JAX-RPC runtime can match SOAP message types to the corresponding
Java objects.
 
Olivier Mocquais
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Thanks for your answer.
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic