package com.hellking.study.webservice;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
/**
* 调用需要验证的Web服务
*/
public class AuthClient {
static final double salary = 50000;
public static void main(String[] args) {
try {
// 配置证书地址及密码
String keystorePassword="123456",truststorePassword="123456";
String keystoreFile = "D:/apache-tomcat-5.5.34/client.keystore";
String truststoreFile = "D:/apache-tomcat-5.5.34/client.truststore";
System.setProperty("javax.net.ssl.keyStore", keystoreFile);
System.setProperty("javax.net.ssl.keyStorePassword",keystorePassword);
System.setProperty("javax.net.ssl.trustStore", truststoreFile);
System.setProperty("javax.net.ssl.trustStorePassword",truststorePassword);
// 服务端的url,需要根据情况更改。
String endpointURL = "https://localhost:8443/axis/services/PersonalTaxService";// Web服务端点地址
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpointURL));
call.setOperationName(new QName("PersonalTaxService", "getTax"));// 设置操作的名称。
// 由于需要使用SSL认证,因此把用户名和密码注释掉了。
//call.getMessageContext().setUsername("hellking");// 设置用户名。
//call.getMessageContext().setPassword("simplewebservices");// 设置密码
call.addParameter("op1", XMLType.XSD_DOUBLE, ParameterMode.IN);// 参数的类型
call.setReturnType(XMLType.XSD_DOUBLE);// 返回的数据类型
Double ret = (Double) call.invoke(new Object[] { new Double(salary) });// 执行调用
System.out.println("使用HTTP协议来作为Web服务的传输协议!");
System.out.println("已经成功调用。请参看服务端的输出!");
System.out.println("输入工资" + salary + "元,应交个人所得税:" + ret);
} catch (Exception e) {
e.printStackTrace();
}
}
}
转载于:https://my.oschina.net/artong999/blog/357111