java调用webService客户端的实现

小马子 小马子 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
哪们大侠给指点一下:我这里用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);
}

}
这样查到的结果是空,这是为什么呀?没有错误提示,程序已经执行完毕,高手请指点,谢啦!
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
小马子
Web 开发 81,108 成员 341,721 内容