很纠结的问题:org.apache.axis2.AxisFault: 服务器未能识别 HTTP 头 SOAPAction 的值
纠结了半天,网上找了很多办法。。。
试来试去都不行。。。用了soapui里取到的报文来用不行。。。。
老是报错:::org.apache.axis2.AxisFault: 服务器未能识别 HTTP 头 SOAPAction 的值
怀疑是代码写错的原因。。。决定不用框架里的代码。。。
单独写。。。
在网上找了几段来试一下。
终于发现有一段可以了:
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import java.net.URL;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
String myCall(String operationCode, HashMap param){
String theRegionCode = "31124";
try{
String endpoint = "http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://WebXml.com.cn/",
"getStockInfoByCode"));
call.addParameter(new QName
(");
//call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA);
call.setUseSOAPAction(true);
call.setReturnClass(String[].class);
call.setSOAPActionURI("http://WebXml.com.cn/getStockInfoByCode");
String[] result = (String[])call.invoke(new Object[]{"sh600477"});
System.out.print("");
}catch(Exception w){}
return "";
}
http://blog.csdn.net/aixiaorenzhe123/article/details/4292465
=====================
和原先老是报错的对比一下:
String theIpAddress = (String)param.get("ip");
try {
//调用webservice的地址
String endPoint = "http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(endPoint));
//调用webservice方法,必须这样调用该方法,是根据soap协议里的方法声明
call.setOperationName(new QName("http://webxml.com.cn/getCountryCityByIp"));
//webservice里method的参数,必须这样定义,否则必然出错
call.addParameter(new QName("http://WebXml.com.cn/", "theIpAddress"),XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://WebXml.com.cn/getCountryCityByIp");
String result = (String) call.invoke(new Object[] { theIpAddress});
// String[] infos = result.split(":", 2);
// if (infos.length == 2) {
// mobileInfos = infos[1].split(" ", 3);
// }
} catch (Exception e) {
e.printStackTrace();
}
return "";
==============
尝试着参照正确的修改一下后居然行了,哈哈哈哈:
String myCall(String operationCode, HashMap param){
String theIpAddress = (String)param.get("ip");
try {
//调用webservice的地址
String endPoint = "http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(endPoint));
//调用webservice方法,必须这样调用该方法,是根据soap协议里的方法声明
call.setOperationName(new QName(""));
//webservice里method的参数,必须这样定义,否则必然出错
call.addParameter(new QName(");
call.setUseSOAPAction(true);
call.setReturnClass(String[].class);
call.setSOAPActionURI("http://WebXml.com.cn/getCountryCityByIp");
String[] results = (String[])call.invoke(new Object[]{theIpAddress});
System.out.print("");
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
============太有才了==========