dynamicclient.java

来自「100多M的J2EE培训内容」· Java 代码 · 共 77 行

JAVA
77
字号
package bible.webservices.rpc.client;



import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import weblogic.soap.WebServiceProxy;
import weblogic.soap.SoapMethod;


/**
 * Class DynamicClient
 * A lightweight client that uses the client.jar file that is produced by
 * WebLogic.  The client.jar file provides the ability to encode and decode
 * SOAP envelopes, transmit the messages via HTTP and the remote interface
 * for Calculator Session Bean.  This client is considered a dynamic client
 * it loads the Web Service's WSDL into a proxy and then uses the proxy to create
 * the apporiate SOAP Method.
 *
 * @author
 * @version %I%, %G%
 */
public class DynamicClient {

  /**
   * Constructor DynamicClient
   *
   *
   */
  public DynamicClient() {}

  /**
   * Method main
   * The main method gets a reference to the Calculator Web Service via
   * its WSDL and then passes two amounts that are to be added.
   * Finally it prints out the result that is returned from the Session
   * Bean.
   *
   *
   * @param args This method makes no use of passed parameters
   *
   * @throws Exception
   *
   */
  public static void main(String[] args) throws Exception {

    Properties props = new Properties();

    props.put(Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.soap.http.SoapInitialContextFactory");

    Context         context = new InitialContext(props);
    WebServiceProxy proxy   = (WebServiceProxy) context
      .lookup("http://localhost:7001/calculator/Calculator/Calculator.wsdl");
    SoapMethod      add     = proxy.getMethod("add");
    long            add1    = 346;
    long            add2    = 5623;

    // a weblogic SoapMethod only returns objects and only
    // takes objects thus the casting into Long
    Long sum = (Long) add.invoke(new Object []{ new Long(add1),
                                                new Long(add2) });

    System.out.println("adding " + add1 + " and " + add2 + " results in "
                       + sum);
  }
}


/*--- Formatted in Bible Style on Thu, Sep 6, '01 ---*/


/*------ Formatted by Jindent 3.24 Gold 1.02 --- http://www.jindent.de ------*/

⌨️ 快捷键说明

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