产生空参数的代码
public static void main(String[] args)
{
Client client;
String smsContent="";
String url="http://zw.yyfdcw.com/fccx/Service.asmx";
try
{
Service service = new Service();
Call call = (Call) service.createCall();
//执行方法设置
call.setOperationName(new QName("http://tempuri.org/", "CxWxjjcx"));
//参数设置
call.addParameter("sjhm", XMLType.XSD_STRING, ParameterMode.IN);
//返回类型设置
call.setReturnType(XMLType.XSD_STRING);
//SOAPAction设置
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://tempuri.org/CxWxjjcx");
//URL设置
call.setTargetEndpointAddress(new URL(url));
//调用WS方法
smsContent = (String) call.invoke(new Object[] { "0000794"});
log.info("webservice method return result=" + smsContent);
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
结果连接.net的WS方法成功,但是参数的值确传不上去,donet的服务端接收到参数都是空。经过一番纠结的查找和测试后,发现是在参数设置时必须加上namespoce的申明(红色代码处)。后将红色代码修改如下后一切OK。
call.addParameter(new QName("http://tempuri.org/","sjhm"), XMLType.XSD_STRING, ParameterMode.IN);