关于java访问别人的webservice接口问题
最近要做一个在java中调用远程webservice接口,根据接口中要提供的参数和方法来调用,我现在用AXIS调用远程的web service的方式来实现,代码如下:
String serviceurl="http://ajcx.hbfy.gov.cn/service/dataService.ws?wsdl";
String namespace = "http://ws.tdh/";
String methodName = "GetAjInfo";
String soapActionURI = "http://ws.tdh/GetAjInfo";
QName qn = new QName("http://ws.tdh/",
"GetAjInfo");
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(serviceurl));
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
call.setOperationName(new QName(namespace, methodName));//
call.addParameter("Userid", org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// param
call.addParameter("Pwd", org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// param
call.addParameter("RequestXML", org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);// param
String uname= ""; //用户名 param1
String pwd=""; //密码 param1
//以下字段逐个base64编码
String fydm="H10";
byte[] fydmByte= fydm.getBytes("UTF-8");
String fydmEcodeStr=Base64.encode(fydmByte);
String ah="(2013)鄂武汉中知初字第02670号";
byte[] ahByte= ah.getBytes("UTF-8");
String ahEcodeStr=Base64.encode(ahByte);
String ajmm="250304";
byte[] ajmmByte= ajmm.getBytes("UTF-8");
String ajmmEcodeStr=Base64.encode(ajmmByte);
String requestxml="<Request><FYDM>"+fydmEcodeStr+"</FYDM> <AH>"+ahEcodeStr+"</AH><AJMM>"+ajmmEcodeStr+"</AJMM></Rquest>";
byte[] requestxmlBate= requestxml.getBytes("UTF-8");
String encodeStr=Base64.encode(requestxmlBate); //整体 base64编码 param1
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
// byte[] cityByte= city.getBytes("UTF-8");
//String citycodeStr=Base64.encode(cityByte);
//call.invoke(new Object[]{city});
//call.invoke(new Object[]{null,null,encodeStr});
//call.invoke(new Object[]{"","",encodeStr});
String result=(String)call.invoke(new Object[]{"","",encodeStr});
System.out.println("result is "+result);
/* for(String r:result){
System.out.println("r======:"+r);
}*/
}
catch (Exception e) {
System.err.println(e.toString());
}
运行测试遇到一个问题很纠结,控制台输出: String serviceurl="http://ajcx.hbfy.gov.cn/service/dataService.ws?wsdl";
String namespace = "http://ws.tdh/";
String methodName = "GetAjInfo";
String soapActionURI = "http://ws.tdh/GetAjInfo";