⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 booksearcherclient.java

📁 JAX-RPC 构建 RPC 服务和客户机,使用 Java API 构建基于 RPC 的 Web 服务
💻 JAVA
字号:
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();      }      if (serviceUrl == null) {        serviceUrl = new URL(SERVICE_URL);      }      call.setTargetEndpointAddress(serviceUrl);           // Select operation to call      call.setOperationName(new QName("http://soapinterop.org/",                             "search"));      // Make call and get result      Object[] results = (Object[])call.invoke(new Object[] { keyword });      return results;    } catch (MalformedURLException e) {      throw new IOException("Error creating service URL at " + SERVICE_URL);    } 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]);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -