StaticClient.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package bible.webservices.rpc.client;
- import javax.naming.Context;
- import javax.naming.InitialContext;
- import java.util.Properties;
- // the remote interface is included in the client.jar file
- import bible.webservices.rpc.CalculatorRemote;
- /**
- * Class StaticClient
- * A lightweight client that uses the client.jar file that is produced by<br>
- * WebLogic. The client.jar file provides the ability to encode and decode<br>
- * SOAP envelopes, transmit the messages via HTTP and the remote interface<br>
- * for Calculator Session Bean. This client is considered a static client<br>
- * because it uses the Remote Interface of the Calculator Session Bean.
- *
- * @author Geoff Schneider
- */
- public class StaticClient {
- /**
- * Constructor StaticClient
- *
- *
- */
- public StaticClient() {}
- /**
- * Method main
- * The main method gets a reference to the Calculator Web Service via<br>
- * its WSDL and then passes two amounts that are to be multiplied. <br>
- * Finally it prints out the result that is returned from the Session<br>
- * Bean.
- *
- * @param args the method makes no use of passed paremeters
- *
- * @throws Exception
- *
- */
- public static void main(String[] args) throws Exception {
- Properties props = new Properties();
- props.put(Context.INITIAL_CONTEXT_FACTORY,
- "weblogic.soap.http.SoapInitialContextFactory");
- props.put("weblogic.soap.wsdl.interface",
- CalculatorRemote.class.getName());
- Context context = new InitialContext(props);
- CalculatorRemote calc = (CalculatorRemote) context
- .lookup("http://localhost:7001/calculator/Calculator/Calculator.wsdl");
- double amount = 34.839283;
- double action = 324232.3432;
- double multReturn = calc.multiply(amount, action);
- System.out.println("The return value from the calculator "
- + "web service when multipling " + amount + " and "
- + action + " is " + multReturn);
- }
- }
- /*--- Formatted in Bible Style on Thu, Sep 6, '01 ---*/
- /*------ Formatted by Jindent 3.24 Gold 1.02 --- http://www.jindent.de ------*/