Professional Documents
Culture Documents
Topics
What is RPC?
JAX-RPC introduction
Creating JAX-RPC based web service
Creating JAX-RPC based web service client
Java-XML mapping for web service
Sample code basic web service and client based on
JAX-RPC
1 Copyright 2003 Ketan A. Pandya
Where are we?
Platform and
toolkit Toolkit and
independent (UDDI) Platform
Service dependent
registry
WSDL
WSDL
Find Publish
service service
..some code..
Function() Function()
code..
client server
3 Copyright 2003 Ketan A. Pandya
Shortcomings of (traditional) RPC
Proprietary protocol
Client and server needs to be using the same programming language
Not suitable for internet
No OO way of calling method
WSDL
document JWSDP
J2SE
Web services Web services
client server
Stubs/
Dyanmic proxy/
Tie classes
DII
JAX-RPC JAX-RPC
runtime SOAP
runtime
JAX-RPC service
Web server
package helloservice;
The service
import java.rmi.Remote; endpoint
interface
Import java.rmi.RemoteException;
public interface HelloIF extends Remote {
public String sayHello(String s) throws
RemoteException;
}
15 Copyright 2003 Ketan A. Pandya
Implement the service
package helloservice;
1. compile-service
2. generate-wsdl
3. generate-mapping from service classes
package names to namespace URIs in the
WSDL and create ties (skeletons)
1. Static stubs
compiled by wscompile before runtime
2. Dynamic stubs
has an interface but fetches the WSDL at runtime
3. Dynamic Invocation Interface
knows no interface - the method names
and signatures
4. A J2EE Application Client
Locate the local web service with JNDI
import javax.xml.rpc.Stub;
import javax.naming.*;
try {
Context ic = new InitialContext();
MyHelloService myHelloService = (MyHelloService)
ic.lookup("java:comp/env/service/MyJAXRPCHello");
((Stub)helloPort)._setProperty
(Stub.ENDPOINT_ADDRESS_PROPERTY,args[0]);
System.out.println(helloPort.sayHello("Jake!"));
System.exit(0);
Generate
Client code
Destination
directory
Input file
CurrentcyExchangePortType.class
CurrentcyExchangeService_Impl.class
31 Copyright 2003 Ketan A. Pandya
Creating JAX-RPC based client from wsdl
teststub.getRate("canada","usa");
.
Code snippet that invokes method on a web service using
stub classes
java TestClient
You will need to include various jar files from JWSDP into
classpath
Another way for client to invoke web service method dynamically without
creating stubs
Flexible: web service parameters can be specified as command line
parameter or as config/property file
Somewhat similar to Apache client
Service name:
CurrencyExchangeService
Port:
CurrencyExchangePortType
Location
http://services.xmethods.com/soap