####环境前提:
- axis 版本为 1.7
- ws 采用 jws 发布
ws发布源码
import javax.xml.ws.Endpoint;
/**
* 服务发布主线程
*/
public class MainPublisher {
public static void main(String[] args) {
Endpoint.publish("http://192.168.2.31:9022/services/auth",new HiveWevServer());
System.out.println("启动成功");
}
}
ws服务
import javax.jws.WebService;
/**
* Webservice Hive查询服务
* @author linx
*/
@WebService
public class HiveWevServer {
public String getAuthInfo(String input){
System.out.println("====== 入参:"+input);
return "";
}
}
axis 调用代码
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
/**
* WebService 接口调用
* @author linx
*/
@org.springframework.stereotype.Service
public class WsHandlerService {
/**
* 调用WebService
*/
public String authPersionalInfo(String qid,String mobile,String name, String idCard){
String result = "";
try{
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://192.168.2.31:9022/services/auth?wsdl");
call.setOperationName(new QName("http://oper.hive.com/", "getAuthInfo"));//
call.addParameter("in0", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//
result = (String)call.invoke(new Object[]{mobile});
}catch(Exception e){
e.printStackTrace();
System.out.println("========Error==========");
}
return result;
}
}
问题
由以上发布的WebService服务,通过axis以上方式调用,ws服务中getAuthInfo的方法始终收到入参为null
解决方法
以下是CSDN查到得有效方案,原贴:CSDN
结合SoapUI分析发现,如果jws通过annotation来发布,或者类似方式,通过axis调用,需要注意两点: 1)在call.setOperationName是必须通过Qname来制定namespaceURI 2)在设定参数时,不使用服务端定义的参数名,而是arg0~argN来定义,也不需制定namespaceURI,上述代码 call.addParameter(new QName(namespace, "TransNo"), XMLType.XSD_STRING, ParameterMode.IN); 修改为 call.addParameter("arg0", XMLType.XSD_STRING, ParameterMode.IN); 有几个参数,即设定几个。 提供参考,可测试试验一下。