java调用webService客户端的实现
小马子 2012-08-17 03:34:52 哪们大侠给指点一下:我这里用apach 的axis2调用别人给的一个webService接口,调用方法如下
package com.cstc.service;
import java.net.URL;
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;
import com.cstc.util.DESCoder;
public class QueryService {
public void queryPersonInfoByName(String idno,String cid){
System.out.println("idno+cid"+idno+" "+cid);
try{
String sKey = "CSgjjWeb";
String endpoint = "http://www.csgjj.com.cn:9001/QueryService.asmx?WSDL";
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL(endpoint));
call.setOperationName(new QName("http://www.csgjj.com.cn:9001/WebService", "QueryPersonalInfo"));
call.addParameter(new QName("http://www.csgjj.com.cn:9001/WebService", "strPersonalName"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName("http://www.csgjj.com.cn:9001/WebService","strIdno"), XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter(new QName("http://www.csgjj.com.cn:9001/WebService","strCustomerID"), XMLType.XSD_STRING, ParameterMode.IN);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://www.csgjj.com.cn:9001/WebService/QueryPersonalInfo");
call.setReturnType(XMLType.XSD_STRING);
String strPersonalName = DESCoder.EncryptAsDoNet(new String("唐晓晖".getBytes("UTF-8")),sKey);
String strIdno = DESCoder.EncryptAsDoNet(idno,sKey);
String strCustomerID = DESCoder.EncryptAsDoNet(cid,sKey);
Object[] params = new Object[3];
params[0] = strPersonalName;
params[1] = strIdno;
params[2] = strCustomerID;
String res = (String)call.invoke(params);
String resDe = DESCoder.DecryptDoNet(res,sKey);
// System.out.println("Right: " + "IbN+8kIFNo/w2Q9GnBI82w==");
// System.out.println("Current: " + (String)params[0]);
System.out.println(resDe);
System.out.println("over queryService");
}catch (Exception ex){
System.out.println("Error: " + ex.getMessage());
}
System.out.println("over catch hou");
}
public static void main(String args[]){
QueryService qs =new QueryService();
qs.queryPersonInfoByName("430104197105050796","12580");
}
}
在这里用的main方法进行的调用,是可以查到想要的数据的。但是如果在servlet中进行调用返回的数据是空的,也没有任何错误提示,代码如下:
public class InsuranceServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
QueryService qs =new QueryService();
qs.queryPersonInfoByName("430104197105050796","12580");
System.out.println("over InsuranceServlet");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
这样查到的结果是空,这是为什么呀?没有错误提示,程序已经执行完毕,高手请指点,谢啦!