webservice的 发布一般都是运用WSDL(web service descriptive language)文件的款式来发布的,在WSDL文件里边,包含这个webservice暴露在外面可供运用的接口。今日查找到了非常好的 webservice provider列表
http://www.webservicex.net/WCF/default.aspx
这上面列出了70多个包含许多方面的free webservice provider,utilities->global weather就可以获取全球的天气预报。
下面我们来看Java怎么通过WSDL文件来调用这些web service:
留意,以下的代码并没有通过真实的测验,只是阐明这些状况,不同版别的Axis相差很大,我们最好以apache网站上的比如为准,这里只是用于阐明其根本用法。
1,直接AXIS调用长途的web service
我觉得这种办法对比合适那些高手,他们能直接看懂XML格局的WSDL文件,我自个是看不懂的,特别我不是专门搞这行的,即便一段时间看懂,后来也就忘记了。直接调用形式如下:
import java.util.Date;
import java.text.DateFormat;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.lang.Integer;
import javax.xml.rpc.ParameterMode;
public class caClient {
public static void main(String[] args) {
try {
String endpoint = "http://www.metabase.cn /ca3/services/caSynrochnized?wsdl";
/* String endpoint = " http://www.jinanwuliangye.com /ca3/services/caSynrochnized?wsdl";
String endpoint = "http://www.tongxinglong.com /ca3/services/caSynrochnized?wsdl";
String endpoint = " http://www.qclchina.com/ /ca3/services/caSynrochnized?wsdl";
String endpoint = "http://www.vipfuxin.com /ca3/services/caSynrochnized?wsdl";
String endpoint = " http://www.minnan888.net /ca3/services/caSynrochnized?wsdl";
String endpoint = " http://www.lcsyt.com/ca3/services/caSynrochnized?wsdl";
String endpoint = " http://lf.yunnanw.cn/ca3/services/caSynrochnized?wsdl";
String endpoint = " http://www.ceocbs.com /ca3/services/caSynrochnized?wsdl";
String endpoint = " http://www.yzbljp.com/ca3/services/caSynrochnized?wsdl";
String endpoint = "http://www.hyyfscl.com /ca3/services/caSynrochnized?wsdl";
String endpoint = " http://www.shuoma.com.cn/ /ca3/services/caSynrochnized?wsdl"; */
//直接引用长途的wsdl文件
//以下都是套路
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("addUser");//WSDL里边描绘的接口称号
call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);//接口的参数
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置回来类型
String temp = "测验人员";
String result = (String)call.invoke(new Object[]{temp});
//给办法传递参数,并且调用办法
System.out.println("result is "+result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}
java调用webservice接口方法