日期:2014-05-17  浏览次数:20765 次

急等回复关于axis2参数无法传入
public static String target = "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx";
/**
 * @param args
 */
public static void main(String[] args){
try{
 // 获得客户端  
RPCServiceClient serviceClient = new RPCServiceClient();
// 可以在该对象中设置服务端的验证信息  
Options options = serviceClient.getOptions();  
EndpointReference targetEPR = new EndpointReference(target);  
options.setTo(targetEPR);
options.setAction("http://WebXml.com.cn/getTVstationDataSet");
// 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,也就是<wsdl:definitions>元素的targetNamespace属性值  
QName opAddEntry = new QName("http://WebXml.com.cn/","getTVstationDataSet");  
// 参数,如果有多个,继续往后面增加即可,不用指定参数的名称  

Object[] opAddEntryArgs = new Object[] {"1"};  
// 返回参数类型,这个和axis1有点区别  
// invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象,表示要调用的方法名;  
// 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[];  
// 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。  
// 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}  
// 如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法,  
// 该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同  
Class[] classes = new Class[] {OMElement.class};
System.out.println("---------->");
OMElement obj=(OMElement)(serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[0]);
System.out.println("============"+obj.toStringWithConsume());
} catch (Exception e) {  
e.printStackTrace();  
}  



}

以上是代码,其中 Object[] opAddEntryArgs = new Object[] {"1"};  这个1传入怎么样也没有结果

------解决方案--------------------
我用httpurlconnection获取过。
String address = "http://webservice.webxml.com.cn/webservices/ChinaTVprogramWebService.asmx";
URL url = new URL(address);
HttpURLConnection http = (HttpURLConnection) url.openConnection();
http.setDoOutput(true);
http.setDoInput(true);
http.setRequestMethod("POST");
http.setUseCaches(false);
http.setRequestProperty("Content-Type", "text/xml");
http.connect();

DataOutputStream out = new DataOutputStream(http.getOutputStream());
String cityId = "-1";
String content = "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2