WEB开发网
开发学院软件开发Java 用 JAX-RPC 构建 RPC 服务和客户机(下) 阅读

用 JAX-RPC 构建 RPC 服务和客户机(下)

 2010-04-06 00:00:00 来源:WEB开发网   
核心提示: 清单 22. 创建 Service 和 Call 实现importjava.io.IOException;importjava.net.MalformedURLException;importjava.net.URL;importjavax.xml.namespace.QName;importj

清单 22. 创建 Service 和 Call 实现

import java.io.IOException; 
import java.net.MalformedURLException; 
import java.net.URL; 
 
import javax.xml.namespace.QName; 
import javax.xml.rpc.ServiceException; 
import org.apache.axis.client.Call; 
import org.apache.axis.client.Service; 
 
public class BookSearcherClient { 
 
 public static final String SERVICE_URL = 
  "http://localhost:8080/axis/BookSearcher.jws"; 
 
 private Service service; 
 private Call call; 
 private URL serviceUrl; 
 
 public BookSearcherClient() { } 
 
 public Object[] search(String keyword) throws IOException { 
  try { 
   if (service == null) { 
    service = new Service(); 
   } 
   if (call == null) { 
    call = (Call)service.createCall(); 
   } 
 
   // placeholder 
   return new Object[]; 
  } catch (ServiceException e) { 
   throw new IOException("Error creating service call: " + e.getMessage()); 
  } 
 } 
 
 public static void main(String[] args) throws IOException { 
  if (args.length != 1) { 
   System.err.println("Usage: java BookSearcherClient [search keyword]"); 
   return; 
  } 
  String keyword = args[0]; 
  BookSearcherClient client = new BookSearcherClient(); 
  Object[] results = client.search(keyword); 
  System.out.println("Returned books for keyword '" + keyword + "':"); 
  for (int i = 0; i<results.length; i++) { 
   System.out.println(" " + results[i]); 
  } 
 } 
}

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:JAX RPC 构建

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接