最近工作中有用到Axis, java调用.net写的webservice, 先将调用过程中所遇到的问题罗列如下:
1: faultString: System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP 头 SOAPAction 的值: 。
这个异常的解决办法:
Axis客户端code上加上如下代码:
call.setSOAPActionURI(namespace+functionName);
2: 明明设置了参数, 缺提示说参数为空的解决办法:
需要Axis调用端的方法参数名称和.net所写的方法的参数名称一致, 否则就会报告这个错误.
调用代码如下:
public void testWgt2() throws Exception{
//.net webService 地址
String url="url";
//.net webService 命名空间
String namespace = "namespace";
//.net webService 需调用的方法
String methodName = "method";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(url));
call.setUseSOAPAction(true);
call.setOperationName(new QName(namespace,methodName));
call.addParameter( new QName(namespace,"username"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter( new QName(namespace,"password"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setSOAPActionURI(namespace+methodName);
String ret = (String) call.invoke(new String[]{"xxx",""});
System.out.println("返回结果---> " + ret);
}