DynamicClient.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- 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 ------*/