找一些webservice的文章来看看http://dns.tlw.cn/22227.htm否则就算别人帮你做了,以后你还是不会
解决方案 »
- 求助:spring 整合ibatis启动报错
- hibernate hql查询语句问题;
- MYECLIPSE新建HTML页面运行后中文乱码
- java 小程序有用吗,没有学过啊!
- hibernate配置文件找不到映射文件user.hbm.xml
- 关于Servlet的forward方法的问题!
- 怎么启动我的JVM??
- Borland试用盘?
- 在win2000下weblogic EJB Deployer 配置ejb时出问题
- 代码块与函数间的同步,其中一个线程只运行了一次
- axis如何用jdbc来访问数据库?
- 如何在TOMCATE的SERVER.XML配置数据源时指定characterEncoding=GBK?
import java.net.*;
import java.util.*;import org.apache.soap.*;
import org.apache.soap.rpc.*;public class TempClient { public static String getName(URL url) throws Exception {
Call call = new Call(); // Service uses standard SOAP encoding
String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
call.setEncodingStyleURI(encodingStyleURI); // Set service locator parameters
call.setTargetObjectURI("urn:xmethods-Temperature");
call.setMethodName("getName"); // Create input parameter vector
// Vector params = new Vector();
// params.addElement(new Parameter("zipcode", String.class, "ss", null));
// call.setParams(params); // Invoke the service ....
Response resp = call.invoke(url, ""); // ... and evaluate the response
if (resp.generatedFault()) {
System.out.println("" + resp.getFault().getFaultString());
// resp.getFault().get
throw new Exception();
} else {
// Call was successful. Extract response parameter and return result
Parameter result = resp.getReturnValue();
return result.getValue() + "";
// Float rate = (Float) result.getValue();
// return rate.floatValue();
} }
public static float getTemp(URL url, String zipcode) throws Exception { Call call = new Call(); // Service uses standard SOAP encoding
String encodingStyleURI = Constants.NS_URI_SOAP_ENC;
call.setEncodingStyleURI(encodingStyleURI); // Set service locator parameters
call.setTargetObjectURI("urn:xmethods-Temperature");
call.setMethodName("getTemp"); // Create input parameter vector
Vector params = new Vector();
params.addElement(new Parameter("zipcode", String.class, zipcode, null));
call.setParams(params); // Invoke the service ....
Response resp = call.invoke(url, ""); // ... and evaluate the response
if (resp.generatedFault()) {
throw new Exception();
} else {
// Call was successful. Extract response parameter and return result
Parameter result = resp.getReturnValue();
Float rate = (Float) result.getValue();
return rate.floatValue();
}
}// Driver to illustrate service invocation
public static void main(String[] args) {
try { URL url = new URL("http://services.xmethods.net:80/soap/servlet/rpcrouter");
// String zipcode= "94041";
String zipcode = "94041";
long time = System.currentTimeMillis();
float temp = getTemp(url, zipcode);
System.out.println("" + (System.currentTimeMillis() - time));
System.out.println(temp); time = System.currentTimeMillis();
url = new URL("http://localhost:80/axis/Test.jws");
String name = getName(url);
System.out.println("" + (System.currentTimeMillis() - time));
System.out.println("name:" + name); } catch (Exception e) {
e.printStackTrace();
}
}
}