staticclient.java
来自「100多M的J2EE培训内容」· Java 代码 · 共 72 行
JAVA
72 行
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 ------*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?